Home windows How to make not closing window?

How to make not closing window?

Author

Date

Category

Greetings. I somewhere saw a piece of C++ code (or C – xs :)) and decided to compile it and look, which will be released ^ _ ^. Here is my code:

# include & lt; stdio.h & gt;
Int Main (int argc, char * argv [])
{
  PrintF ("Hello, World \ N");
  Return 0;
}

uh … as it were :). After compiling under Windows appears .exe file. When you click on it, the console is opened (for a split second) and closes … How to make it not closed? 🙂

PS. Profi – Film No Muntore – C++ has not yet digged and find out interesting :).
PPS. Give a promise that Microsoft does not show this piece of code – otherwise it is not necessary to introduce it in your programs: DDDDDD
PPPs. Thanks in advance 🙂


Answer 1, Authority 100%

Option with System ("Pause")

# include & lt; Cstdio & gt;
#Include & lt; Cstdlib & gt; // Here is the System () function
Int Main (int argc, char * argv [])
{
  PrintF ("Hello, World \ N");
  SYSTEM ("PAUSE");
  Return 0;
}

System () function calls a new command interpreter instance and runs a command from a row transmitted to it as a parameter.

c getchar () :

# include & lt; Cstdio & gt;
Int Main (int argc, char * argv [])
{
  PrintF ("Hello, World \ n");
  getchar ();
  Return 0;
}

The getchar () function is used to read and transfer any variable entered in the symbol command prompt. It will wait until something is introduced. Here it is just waiting and after pressing Enter continues the execution of the program, and the entered symbol is not transmitted. Therefore, the false call.


Answer 2, Authority 50%

And finally, the easiest and most terrible option: for (;;);

Creepy, he downloads the core of the CPU 100%.


Answer 3, Authority 25%

Several options, add System ("Pause"; Make a fictitious input: cin.get (); getchar (); etc. , something should stop, experiment;)


Answer 4, Authority 25%

as an option. Create a .bat file in a folder with EXE-shniks with such content “CMD” (without pitches). When it starts it, the console opens and you already run the desired file from it.


Answer 5

And you can also create a BAT or CMD file in a folder with a program with such content:

Program
Pause

where Program is the name of the program.
I start this commander of other people’s console programs to read the output.


Answer 6

Hold the code (working, but incorrect :)), at the same time we learn the STDIO streaming functions:

# include & lt; stdio.h & gt;
Int Main (int argc, char * argv [])
{
  PrintF ("Hello, World \ N");
  Printf ("Press Enter for Exit ... \ n");
  SCANF ("ENTER KEY");
  Return 0;
}

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