C++ 文件问题
data文件里的东西是liming 1 200
xiaoqiang 2 300
xiaozhu 3 100
xiaokai 4 600
本来是要执行把100改为500 然后放到data1 就这么简单 可是 为什么后面多了 4 600这个尾巴 帮忙改正下
#include<cstdlib>
#include<conio.h>
#include<fstream>
#include<iostream>
#include<string>
#include <sstream>
using namespace std;
ofstream fout("F:\\data1.txt");
class A
{
private:
string m_name;
int m_index;
int m_count;
public:
A(string name,int index,int count)
{
m_name=name;
m_index=index;
m_count=count;
}
void Modify(int count)//读入cout
{
m_count=count;
}
void Output()
{
cout<<"Name is:"<<m_name<<" ;Index is:"<<m_index<<" ; Count is:"<<m_count<<endl;
}
void Write()
{
fout<<m_name<<" "<<m_index<<" "<<m_count<<endl;
}
};
int main()
{
ifstream fin("F:\\data.txt");
if(!fin)
{
cout<<"Open file error!"<<endl;
return 0;
}
string name;
int index,count;
while(fin)
{
fin>>name;
fin>>index;
fin>>count;
A obj(name,index,count);
obj.Output();
if(count==100)
obj.Modify(500);
cout<<"修改后的结果:"<<endl;
obj.Output();
obj.Write();
}
return 0;
}