-1

I'm trying to learn c++ and this is a total noob question but how could I pause the program so I can read what it displayed its only staying up for a fraction of a second (about the same as a batch file with a error)

Its not a code issue if I hold CNT+f10 I can read it and it worked

Putting system ("pause"); worked well enough for me to read it but it is still not running properly

user5787634
  • 1
  • 1
  • 2
  • Assuming windows, have a look at: http://stackoverflow.com/questions/11512821/how-to-stop-c-sharp-console-applications-of-closing-automatically – John3136 Jan 14 '16 at 23:45
  • Couldn't even take the time to spell "noob" properly... – Lightness Races in Orbit Jan 14 '16 at 23:45
  • Type Ctrl+F10 then? I don't see the problem if you have a method that does what you want. – Lightness Races in Orbit Jan 14 '16 at 23:47
  • 1
    @John3136 The answers to that question are disastrous as answers to this question. Treating a C++ terminal problem like a C# GUI program would be a *huge* mistake. – David Schwartz Jan 14 '16 at 23:49
  • 3
    This is an issue with how you are launching the code, not the code. How are you launching the code? Generally speaking, console programs should be launched from a console. – David Schwartz Jan 14 '16 at 23:50
  • I usually just check [IsDebuggerPresent()](https://msdn.microsoft.com/en-us/library/windows/desktop/ms680345(v=vs.85).aspx) at the end of main(), and, if it returned true, I call `std::cin.get();` to make the program pause until I hit Enter. It basically mimics Ctrl-F5 behavior when debugging out of Visual Studio, which seems to be the behavior @user5787634 is looking for. – Mark Waterman Jan 14 '16 at 23:59

1 Answers1

-2
cout << "Press any key to continue...";
cin >> pause;

or

System("pause");
  • 7
    Both of these suggestions are bad. The first one is bad because it makes the program unusable in a pipeline or in other automated contexts. The second one is bad because you have no idea what "pause" does on his platform. For all you know, it pauses the cooling system on his home nuclear reactor. – David Schwartz Jan 14 '16 at 23:50
  • 1
    dude, this guy just wrote that he trying to learn c++, do you really think that he will do some pipelines, or that he have a nuclear reactor. – Nino Mirza Mušić Jan 14 '16 at 23:56
  • 2
    No, I'm just explaining why these are bad suggestions. When someone is trying to learn, it's extremely important not to teach them bad things as if they were the right way to do things. – David Schwartz Jan 15 '16 at 02:02