首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

个文件流对象,为啥不能关联2个文件

2014-01-01 
个文件流对象,为什么不能关联2个文件#includeiostream#includefstreamusing namespace stdintmain(){

个文件流对象,为什么不能关联2个文件
#include<iostream>
#include<fstream>
using namespace std;

int  main(){
char temp[200];
ifstream fp;

fp.open("d:\\root.txt");
if(!fp){
cout<<" error"<<endl;
exit(1);
}
while(fp)
{
fp.getline(temp,200);
cout<<temp<<endl;
}
fp.close();

fp.open("d:\\out.txt");
if(!fp){
cout<<" error"<<endl;
exit(1);
}
while(fp)
{
fp.getline(temp,200);
cout<<temp<<endl;
}
fp.close();
}
为什么fp.open("d:\\out.txt");时,文件无法打开,即fp为假
[解决办法]
请记得clear再open第二个。
另外,复用流对象,可以说永远是一个糟糕想法。

热点排行