fork download
  1. #include <string>
  2. #include <iostream>
  3.  
  4. void game(const std::string& from);
  5.  
  6. class PathTracker {
  7. std::string m_path;
  8.  
  9. public:
  10. PathTracker(const std::string& path_, const char* func_)
  11. : m_path(path_)
  12. {
  13. m_path += ">";
  14. m_path += func_;
  15. std::cout << m_path << " +enter+" << std::endl;
  16. }
  17.  
  18. const std::string path() const { return m_path; }
  19.  
  20. ~PathTracker() { std::cout << m_path << " -return-" << std::endl; }
  21. };
  22.  
  23. void gameSummary(const std::string& from)
  24. {
  25. PathTracker p(from, "gameSummary");
  26. std::cout << "[game summary]" << std::endl;
  27. }
  28.  
  29. void isTrue(const std::string& from)
  30. {
  31. PathTracker p(from, "isTrue");
  32. std::cout << "Another game? ";
  33. char answer;
  34. std::cin >> answer;
  35. std::cout << "Got " << answer << std::endl;
  36. if (answer == 'Y' || answer == 'y') {
  37. game(p.path());
  38. }
  39. gameSummary(p.path());
  40. }
  41.  
  42. void game(const std::string& from)
  43. {
  44. PathTracker p(from, "game");
  45. std::cout << "[get user input]" << std::endl;
  46. isTrue(p.path());
  47. }
  48.  
  49. int main(int argc, const char* argv[])
  50. {
  51. game("main");
  52. }
  53.  
Success #stdin #stdout 0s 3480KB
stdin
Y
N
stdout
main>game +enter+
[get user input]
main>game>isTrue +enter+
Another game? Got Y
main>game>isTrue>game +enter+
[get user input]
main>game>isTrue>game>isTrue +enter+
Another game? Got N
main>game>isTrue>game>isTrue>gameSummary +enter+
[game summary]
main>game>isTrue>game>isTrue>gameSummary -return-
main>game>isTrue>game>isTrue -return-
main>game>isTrue>game -return-
main>game>isTrue>gameSummary +enter+
[game summary]
main>game>isTrue>gameSummary -return-
main>game>isTrue -return-
main>game -return-