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

为什么读取文件,文件内容会被改掉解决办法

2012-02-21 
为什么读取文件,文件内容会被改掉/*大家看看下面这段程序,为什么我每一次运行程序以后,order.txt中的内容

为什么读取文件,文件内容会被改掉
/*大家看看下面这段程序,为什么我每一次运行程序以后,order.txt中的内容会被修改,一般都是第一行的第一个字符会被拷贝一次,例如原文件是:3   5   7   dall
运行程序以后,便成了:3   3   5   7   dall了。*/
#include   <fstream>
#include   <iostream>
#include   <string>
using   namespace   std;

typedef   struct{
int   opr_type;
int   time_loop;
int   time_bet;
string   path;
}myCtr;

int   main(void)
{
myCtr   ctr1;
fstream   file1,   file2;

file2.open( "order.txt ");
file1.open( "test.txt ");

file2   > >   ctr1.opr_type
> >   ctr1.time_loop
> >   ctr1.time_bet
> >   ctr1.path;

file1   < <   ctr1.opr_type   < <   '   '
< <   ctr1.time_loop   < <   '   '
< <   ctr1.time_bet   < <   '   '
< <   ctr1.path   < <   endl;

file1.close();
file2.close();

return   0;
}



[解决办法]
ofstream file1
ifstream file2;

[解决办法]
你换个编译器再试。

热点排行