dev C++里运行以后就跳出来,看不到结果????

运行之后跳出来一下,就看不到结果了
比如这个是怎么加的呢?? 我试了所有的方法都不能解决。//。。

#include<string>
#include<fstream>
#include<iostream>
#include <stdio.h>

using namespace std;
int main()
{
fstream tfile("readme.txt",ios::out|ios::in);
if(tfile.fail())
{
cout<<"Can't open the file"<<endl;
exit(0);
}
tfile<<"hello"<<endl;
string line;
///////////添加就可以看到,文件已经失败了!
if(tfile.fail())
{
cout<<"Can't open the file"<<endl;
tfile.close(); //关闭然后再打开
tfile.open("readme.txt");
}

tfile.seekg(0,ios::beg);
while(getline(tfile,line))
{
cout<<line<<endl;//一定要有endl
}
return 0;

在return之前加一个getch()就行了
ps:要加<conin.h>头文件;
eg:
#include <stdio.h>
#include <conio.h>
int max(int *q1,int *q2)
{
if(*q1>*q2)
return *q1;
else
return *q2;
}
int main()
{
int a,b,c,*p1,*p2,*p3,temp;
scanf("%d %d %d",&a,&b,&c);
p1=&a;p2=&b;p3=&c;
temp=max(p1,p2);
//printf("%d",max(&temp,p3));
if(temp==*p1)
printf("%d",max(p1,p3));
else
printf("%d",max(p2,p3));
getch();
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2008-11-25
程序运行完了自动会关闭,当然看不到结果了。
main函数里面return语句之前加上cin.get();或者system("pause");再试试
第2个回答  2008-11-25
加个死循环也成
while(1){}
第3个回答  2008-11-25
方法1:
需要输入后跳出程序:
在Return 0前加上一个getchar()
方法2:
调用Windows内部函数(好像是叫这名):
在Return 0前加上一个SYSTEM("PAUSE")
方法3:
在终端下运行:( 推荐!!! )
点击 开始 —〉 运行 —〉 CMD
然后将.exe文件拉入后按“回车”
相似回答