我开始在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;
}
我漏了哪一行?
当前回答
只需在代码的末尾添加system("pause"),然后像这样返回0
#include <stdlib.h>
int main()
{
//some code goes here
system("pause")
return 0;
}
其他回答
标准的方法是在return语句之前使用cin.get()。
int _tmain(int argc, _TCHAR* argv[])
{
cout << "Hello World";
cin.get();
return 0;
}
在返回行上放置断点。
你在调试器中运行它,对吧?
就在你的include之后 YW std:: cin.clear ();//重置任何错误标志 std:: cin.ignore (std:: numeric_limitsstd:: streamsize:: max (), ' \ n ');//忽略输入缓冲区中的任何字符,直到找到一个输入字符 std:: cin.get ();//从用户那里再获取一个字符
只需在代码的末尾添加system("pause"),然后像这样返回0
#include <stdlib.h>
int main()
{
//some code goes here
system("pause")
return 0;
}
你可以使用cin.get();或cin.ignore ();在return语句之前,避免控制台窗口关闭。