Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

childProgram.cpp 1015B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. std::ofstream log("childProgram.log");
  9. // Output for read test.
  10. if (argc == 2) {
  11. // Write a single line and exit.
  12. if (std::string(argv[1]) == "write") {
  13. log << "Command is \"write\". Returning \"This is a test\"" << std::endl;
  14. std::cout << "This is a test";
  15. std::cout.flush();
  16. goto exit;
  17. }
  18. // Exit without writing anything.
  19. if (std::string(argv[1]) == "quit") {
  20. log << "Command is \"quit\". Exiting" << std::endl;
  21. goto exit;
  22. }
  23. }
  24. char ch;
  25. log << "Received \"";
  26. while (std::cin >> ch) {
  27. // Exit?
  28. if ('q' == ch) {
  29. log << (char) ch << "\"" << std::endl;
  30. break;
  31. }
  32. std::cout << (char) std::toupper(ch);
  33. std::cout.flush();
  34. log << (char) ch;
  35. log.flush();
  36. }
  37. exit:
  38. log.close();
  39. return 25;
  40. }