请C\C++高手给予指点啊
oura 2013-07-15 10:06:41 [code=c]# include<iostream>
# include <fstream>
use namespace std;
void fun()
{
int a[20];
int temp;
ifstream infile("F:\\file2.dat");
ofstream outfile("F:\\file2.dat");
if(!infile)
{
cerr<<"open file2.dat error"<<endl;
exit(1);
}
if(!outfile)
{
cerr<<"open file2.dat error"<<endl;
exit(1);
}
for(int i=0;i<20;i++)
infile>>a[i];
for(int i=0;i<19;i++)
for(int j=i;j<20;j++)
{
if(a[i]>a[j])
{temp=a[i];a[i]=a[j];a[j]=temp;}
}
cout<<"output array"<<endl;
for(int i=0;i<20;i++)
cout<<a[i]<<" ";*/
infile.close();
cout<<"output data into fil2.dat"<<endl;
for(int i=0;i<20;i++)
{
outfile<<a[i]<<" ";
cout<<a[i]<<" ";
}
outfile.close();
}
int main()
{
fun();
return 0;
}
请问代码中着红色标记的两行对吗?
在编程中能否这样同时以输入和输出的方式同时打开同一个文件?
程序在编译时能通过,但执行结果是错误的,请高手们给予指点,不甚感激!