Home c++ Using system (“pause”)

Using system (“pause”)




Answer 1, authority 100%

Attention! The correct answer to the question has already been given by the user Andrew : function system is declared in the header file cstdlib (or stdlib.h ). Please do not add new answers like “I connected N and it worked “, where N is another heading that indirectly includes cstdlib.

In Microsoft Visual Studio , for example, when launched by Ctrl + F5 , the IDE itself will launch the program as if it were expected input at the end.

More solutions:

  • MS function _getch () from & lt; conio.h & gt;
  • std :: cin & gt; & gt; c , where c is char c . However, you will also have to press enter .
  • Breakpoint at the closing parenthesis int main (...) {} .
  • You can think of something else.

Answer 2, authority 94%

Stop doing the nonsense of inscribing some system ("pause") and other garbage in the code. There shouldn’t be anything like this in a console application.

If you are developing a console application for MS Visual Studio, then go to the project settings, the Linker section and set the SubSystem setting to CONSOLE

 enter image description here

Then make it a habit to start your application not in debug mode (“Start Debugging”, F5), but in “Start Without Debugging” mode (Ctrl + F5). In this case, the console window will not close itself, but will remain on the screen until the next key press.

Running programs under the debugger (F5) is intended for situations when you have breakpoints in your code, i.e. when running under the debugger, you shouldn’t worry about the automatic closing of the window at all.

In VS2017, starting with a certain version, there was a debugger option that prevents the console window from closing when the program ends, regardless of whether you ran your program in debug mode

 enter image description here

Answer 3, authority 44%

You need to include the cstdlib library, because system is declared there.

# include & lt; cstdlib & gt;

Answer 4, authority 6%

Most likely, the getchar () call will not work because there is already a character in the input buffer. This is usually a line feed left over from scanf . Therefore, you must first read it, and only then another one that the user clicks:

getchar (), getchar ();

And of course, this case should be deleted as soon as it is no longer needed.

PS: If the user presses the spacebar before entering, it will still not work.

Answer 5

// try the same action
# include & lt; iostream & gt;
using namespace std;
int main () {
cout & lt; & lt; "Press Enter \ n to continue";
cin.get (); // can be several times, for correctness
return 0;

Answer 6

if builder then
#include & lt; iostream.h & gt;

Answer 7

# include & lt; iostream & gt;
using namespace std;

How are you, comrade, the most standard iostream library, haven’t tried it ??? It also allows you to use cin cout and cerr (maybe you don’t know), and looking at the tips of an intellectual (he appeared for C++ in VS2012), she generally has a lot of things (or rather, specifically in std).

Answer 8

I also had this problem. I solved it by including the Windows.h

directive in the code

For those who have not encountered this error:
Do not use the words that are written in books as an argument. Our goal is to solve the problem.
Despite the fact that the system operator is included in the standard library stdlib.h , you will sometimes have to include the Windows.h directive for the operator to work properly system .

# include & lt; iostream & gt;
#include & lt; windows.h & gt;
using namespace std;
int main ()
cout & lt; & lt; "\ n Hello World!" & lt; & lt; endl;
system ("pause");
return 0;

Answer 9

try Directive # include & lt; stdio.h & gt;
and insert system ("pause \ n");
For the operator getch (); the directive #include & lt; conio.h & gt ;!

Answer 10

I solved this problem like this

# include & lt; iostream & gt;
using namespace std;
int main (int argc, char ** argv)
cout & lt; & lt; "After execution, there is a pause for you" & lt; & lt; endl;
  system ("pause");
  return 0;

Ie you need to add input arguments for the main () function, namely

int main (int argc, char ** argv)

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions