现在的位置: 首页 > 综合 > 正文

VS2010/2008 C++ program error:output window disappears 运行窗口自动退出

2013年09月08日 ⁄ 综合 ⁄ 共 1025字 ⁄ 字号 评论关闭

在visul studio 2010和2008里面运行如下c++程序:

#include <iostream>
using namespace std;

int main()
{
 int a, b, c;
 int f(int x, int y, int z);
 cin>>a>>b>>c;
 c=f(a,b,c);
 cout<<c<<endl;
 return 0;
}

int f(int x, int y, int z)
{
 int m;
    if(x<y) m=x;
 else m=y;
 if(z<m) m=z;
 return m;
}

 

会出现如下内容且窗口自动退出:

'521.exe': Loaded 'D:\Program Files\521\Debug\521.exe', Symbols loaded.
'521.exe': Loaded 'C:\Windows\System32\ntdll.dll', Cannot find or open the PDB file
'521.exe': Loaded 'C:\Windows\System32\kernel32.dll', Cannot find or open the PDB file
'521.exe': Loaded 'C:\Windows\System32\KernelBase.dll', Cannot find or open the PDB file
'521.exe': Loaded 'C:\Windows\System32\msvcp100d.dll', Symbols loaded.
'521.exe': Loaded 'C:\Windows\System32\msvcr100d.dll', Symbols loaded.
The program '[5960] 521.exe: Native' has exited with code 0 (0x0).

 

需要加 system(“pause”)

原因:system( "pause ")就是表示接收一个输入,比如显示的   按任意键继续... 

修改后程序为:

#include <iostream>
using namespace std;

int main()
{
 int a, b, c;
 int f(int x, int y, int z);
 cin>>a>>b>>c;
 c=f(a,b,c);
 cout<<c<<endl;
 system("pause");
 return 0;
 
}

int f(int x, int y, int z)
{
 int m;
    if(x<y) m=x;
 else m=y;
 if(z<m) m=z;
 return m;
}

 

抱歉!评论已关闭.