标题:一个文件程序,里面有点小问题
取消只看楼主
lyj23
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:168
专家分:140
注 册:2010-10-31
结帖率:86.21%
已结贴  问题点数:10 回复次数:1 
一个文件程序,里面有点小问题
我用DEV C++
程序代码:
#include <fstream>
#include <conio.h>
#include <iostream>
using namespace std;

int main()
{
int a[10],max,i,order;
ofstream outfile("exercise_4.txt",ios::out|ios::trunc);
if(!outfile)
{

 cerr<<"can't open this file"<<endl<<"open error"<<endl;

 getchar();

 exit(0);
}
cout<<"put 10 number in this:"<<endl;
for(i=0;i<10;i++)

 {cin>>a[i];

 outfile<<a[i]<<" ";}
outfile.close();
//上半部分
ifstream infile("exercise_4.txt",ios::in);
if(!infile)
{

 cerr<<"can't open this file"<<endl<<"open error"<<endl;

 getchar();

 exit(0);
}
for(i=0;i<10;i++)
{

 infile>>a[i];

 cout<<a[i]<<" "<<endl;
}
cout<<endl;
max=a[0];
for(i=1;i<10;i++)

 if(a[i]>max)
  {
   max=a[i];
   order=i;
  }
cout<<"max="<<max<<endl;
cout<<"order="<<order<<endl;
getch();  //这里我写getch();就不会在执行完上半部分后闪屏而过,用getchar();为什么就会闪屏?
infile.close();   //这两个函数不是差不多吗,只不过显示和不显示。。
cout<<"The porgram is end."<<endl;
return 0;
}
2011-05-07 15:19
lyj23
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:168
专家分:140
注 册:2010-10-31
得分:0 
我说的闪屏就是DEVC++程序结束后没有看的时间!
直接一闪就没了!
写getchar()||getch()是为了等待键入字符!
为什么有时候getchar()写了照样闪,getch()就不闪了?
2011-05-08 08:28



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-339079-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.124563 second(s), 8 queries.
Copyright©2004-2025, BCCN.NET, All Rights Reserved