开发者

How can i make that the console, with the output, will not disapear after the program ends in VS 2010 express C++

How can i make that the console, with the output, will not disapear after the program ends in VS 2010 express C++?

i write in c and not in c++, soo i need a 开发者_开发技巧function and include path to library.

Thanks


You can simply poll for input. This performs a block so that the function only returns when the user gives more input - usually enter. If you're on Windows you can also use system("PAUSE").


You have a few options:

  • Run the program from command prompt
  • Add a getchar() before you return from main.
  • Add system("pause") before you return from main


Pressing Ctrl+F5 ("Build -> Start Without Debugging") will run the application and automatically wait for a keypress before closing the console. However, as the name says, you do not have a debugger attached then.


int waitforenter(void) {
    int ch;
    puts("press ENTER (maybe twice)");

    /* get rid of a (possibly) pre existing '\n' */
    do {
        ch = getchar();
    } while ((ch != EOF) && (ch != '\n'));

    /* and again */
    if (ch != EOF) do ch = getchar(); while ((ch != EOF) && (ch != '\n'));
    return ch;
}

And then call waitforenter() right before the end of your main() function.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜