fork download
  1. #include <iostream>
  2. #include <fstream>
  3. #include <string>
  4. #include <list>
  5. #include <exception>
  6. #include <errno.h>
  7. #include <stdlib.h>
  8.  
  9. int main()
  10. {
  11. try
  12. {
  13. std::ifstream f("teste.txt");
  14.  
  15. if(!f)
  16. {
  17. std::cerr << "ERROR: Cannot open 'teste.txt'!" << std::endl;
  18. // exit(1);
  19. }
  20. std::string line;
  21. std::list<std::string> mylist;
  22.  
  23. while (std::getline(f,line))
  24. {
  25. mylist.push_back(line);
  26. std::cout << mylist.back() << std::endl;
  27. }
  28. }
  29. catch(const std::exception& ex)
  30. {
  31. std::cerr << "Exception: '" << ex.what() << "'!" << std::endl;
  32. exit(1);
  33. }
  34.  
  35. exit(0);
  36. }
  37.  
Success #stdin #stdout #stderr 0s 2860KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
ERROR: Cannot open 'teste.txt'!