fork download
  1. #include <iostream>
  2. #include <strstream>
  3. #include <memory>
  4.  
  5. using namespace std;
  6. bool fillScreen(std::ostream&);
  7.  
  8. int main ()
  9. {
  10. auto_ptr<ostrstream> screen(new ostrstream);
  11. bool succ = false;
  12. try
  13. {
  14. succ = fillScreen(*screen);
  15. }catch(std::exception &ex)
  16. {
  17. std::cerr << ex.what() << std::endl;
  18. }
  19. if(succ)
  20. {
  21. std::cout << "SCREEN Content is : " << screen->str() << std::endl;
  22. }
  23. else
  24. {
  25. std::cout << "NOTHING ON SCREEN Object " << std::endl;
  26. }
  27. }
  28.  
  29. bool fillScreen(ostream &scr)
  30. {
  31. unsigned long idx = 0;
  32. scr.exceptions(std::ios::badbit);// throws exception in windows but not in Linux.
  33. while (idx++ < 999999999)
  34. {
  35. scr << "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH BLAHBLAHBLAH_BLAH_" << " : " ;
  36. scr << "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_";
  37. scr << "BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_BLAHBLAHBLAH_BLAH_"<< std::endl;
  38. /*if(!(idx %100000))
  39.   {
  40.   std::cout << "Reached iteration: " << idx << std::endl;
  41.   }*/
  42. }
  43. return true;
  44. }
Success #stdin #stdout #stderr 0.82s 4456KB
stdin
Standard input is empty
stdout
NOTHING ON SCREEN Object 
stderr
std::bad_alloc