windows “不要让 cmd 窗口自动关闭” - 我该怎么做?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8276950/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
"Dont let cmd window to close automatically" -how can i do this?
提问by Jeegar Patel
see i have compile one c program and prepare one a.exe
看到我已经编译了一个 c 程序并准备了一个 a.exe
Now when ever i click on a.exe
现在每当我点击 a.exe
cmd windows opens
cmd窗口打开
a.exe run
a.exe 运行
and automatically close that windows.
并自动关闭该窗口。
What should i do in program or anywhere so this way after running that a.exe that cmd windows don't close automatically.
在运行 cmd 窗口不会自动关闭的 a.exe 之后,我应该在程序中或任何地方以这种方式做什么。
回答by a_horse_with_no_name
Create a batch file with the following content:
创建一个包含以下内容的批处理文件:
a.exe
pause
Then start the batch file
然后启动批处理文件
As an alternative you could add a line to your C program that prompts the user for input before exiting.
作为替代方案,您可以在 C 程序中添加一行,在退出之前提示用户输入。
回答by mtahmed
Use system("PAUSE");
just before the return
in your main()
.
使用system("PAUSE");
之前只是return
在你的main()
。
回答by Cyclonecode
回答by David Hu
You can run your program from the command prompt:
您可以从命令提示符运行您的程序:
Press winkey + R to open up the run
prompt, and type in cmd
. Then press enter. Now navigate to the directory where your program is by using the cd
command, and run it from there.
按 winkey + R 打开run
提示,然后输入cmd
. 然后按回车。现在使用cd
命令导航到您的程序所在的目录,并从那里运行它。
Alternatively, you can add this to the end of your program:
或者,您可以将其添加到程序的末尾:
#include <stdio.h>
int main() {
// ...
getchar();
return 0;
}