看我编译了一个c程序并准备了一个a.exe
现在,当我点击a.exe
时cmd窗口打开
a.exe运行
并自动关闭那些窗口。
我应该在程序中或任何地方执行此操作,以便在运行cmd窗口不会自动关闭的a.exe之后执行此操作。
答案 0 :(得分:4)
使用以下内容创建批处理文件:
a.exe
pause
然后启动批处理文件
作为替代方案,您可以在C程序中添加一行,在退出之前提示用户输入。
答案 1 :(得分:2)
您可以使用getchar()
来读取stdin
中的单个字符:
#include <stdio.h>
int main(int argc,char** argv) {
// getchar() waits until its able to read a character from stdin
getchar();
return 0;
}
答案 2 :(得分:2)
在system("PAUSE");
的{{1}}之前使用return
。
答案 3 :(得分:1)
您可以从命令提示符运行程序:
按winkey + R打开run
提示,然后输入cmd
。然后按Enter键。现在使用cd
命令导航到程序所在的目录,然后从那里运行。
或者,您可以将其添加到程序的末尾:
#include <stdio.h>
int main() {
// ...
getchar();
return 0;
}