fork download
  1. #include <iostream>
  2.  
  3. int openfile(const std::string& name)
  4. {
  5. if (name == "fail") {
  6. return 10;
  7. }
  8.  
  9. return 0;
  10. }
  11.  
  12. int handlefiles()
  13. {
  14. int code;
  15.  
  16. code = openfile("/home/Knjagskij/file1.txt");
  17. if (code != 0) return code;
  18. code = openfile("/etc/passwd");
  19. if (code != 0) return code;
  20. code = openfile("fail"); // Oooops...
  21. if (code != 0) return code;
  22. code = openfile("/etc/hosts");
  23. if (code != 0) return code;
  24.  
  25. return 0;
  26. }
  27.  
  28. int main() {
  29. int code = handlefiles();
  30. if (code != 0) {
  31. std::cout << "Unable to open some file because of " << code << std::endl;
  32. }
  33. return 0;
  34. }
Success #stdin #stdout 0s 3412KB
stdin
Standard input is empty
stdout
Unable to open some file because of 10