我开始在Visual c++和我想知道如何保持控制台窗口。
例如,这将是一个典型的“hello world”应用程序:
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello World";
return 0;
}
我漏了哪一行?
我开始在Visual c++和我想知道如何保持控制台窗口。
例如,这将是一个典型的“hello world”应用程序:
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello World";
return 0;
}
我漏了哪一行?
当前回答
在返回行上放置断点。
你在调试器中运行它,对吧?
其他回答
sin .get()或system("PAUSE")。 我没听说过你可以用return(0);
只需要在main的最后一个花括号上加一个断点。
int main () {
//...your code...
return 0;
} //<- breakpoint here
它适合我,不需要调试就可以运行。它还会在到达断点之前执行析构函数,这样您就可以检查在这些析构函数上打印的消息(如果有的话)。
只需在代码的末尾添加system("pause"),然后像这样返回0
#include <stdlib.h>
int main()
{
//some code goes here
system("pause")
return 0;
}
就在你的include之后 YW std:: cin.clear ();//重置任何错误标志 std:: cin.ignore (std:: numeric_limitsstd:: streamsize:: max (), ' \ n ');//忽略输入缓冲区中的任何字符,直到找到一个输入字符 std:: cin.get ();//从用户那里再获取一个字符
另一种选择是使用
#include <process.h>
system("pause");
虽然这不是很可移植,因为它只能在Windows上工作,但它会自动打印
按任意键继续…