我开始在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;
}
我漏了哪一行?
当前回答
标准的方法是在return语句之前使用cin.get()。
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello World";
cin.get();
return 0;
}
其他回答
只需在_tmain方法的右括号中添加一个断点。这是一种更简单的方法,而且你不需要为了调试而添加代码。
我的观点:
选择1:在main()的末尾添加断点
选择2:在返回0之前添加这段代码:
std::cout << "Press ENTER to continue..."; //So the User knows what to do
std::cin.ignore(std::numeric_limits<std::streamsize>::max(), '\n');
对于std::numeric_limits,您需要包含<iomanip>
就在你的include之后 YW std:: cin.clear ();//重置任何错误标志 std:: cin.ignore (std:: numeric_limitsstd:: streamsize:: max (), ' \ n ');//忽略输入缓冲区中的任何字符,直到找到一个输入字符 std:: cin.get ();//从用户那里再获取一个字符
我包含#include <conio.h>,然后添加getch();就在返回0之前;线。这是我在学校学到的。我看上面提到的方法有很大不同。
sin .get()或system("PAUSE")。 我没听说过你可以用return(0);