You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

childProgram.cpp 800B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include <iostream>
  2. #include <fstream> // debug
  3. #include <string>
  4. #include <thread>
  5. #include <chrono>
  6. int
  7. main(int argc, char *argv[]) {
  8. // Output for read test.
  9. if (argc == 2) {
  10. // Write a single line and exit.
  11. if (std::string(argv[1]) == "write") {
  12. std::cout << "This is a test";
  13. std::cout.flush();
  14. return 25;
  15. }
  16. // Exit without writing anything.
  17. if (std::string(argv[1]) == "quit") {
  18. return 25;
  19. }
  20. }
  21. std::ofstream log("childProgram.log");
  22. char ch;
  23. while (std::cin >> ch) {
  24. // Exit?
  25. if ('q' == ch) {
  26. break;
  27. }
  28. std::cout << (char) std::toupper(ch);
  29. std::cout.flush();
  30. log << (char) std::toupper(ch);
  31. log.flush();
  32. }
  33. log.close();
  34. return 25;
  35. }