<br>
#include "stdafx.h"<br>
#include <iostream><br>
#include <fstream><br>
#include <strstream><br>
#include <string><br>
#include <vector><br>
using
namespace
std;<br>
<br>
const
string inFileName=
"testData.txt"
;<br>
const
string outFileName=
"outData.txt"
;<br>
<br>
struct
Hero<br>
{<br>
string name;<br>
int
age;<br>
char
sex;<br>
double
weight;<br>
string color;<br>
vector<
int
> number;<br>
};<br>
<br>
vector<hero> heroList;<br>
<br>
int
_tmain(
int
argc, _TCHAR* argv[])<br>
{<br>
ifstream fin;<br>
fin.open(inFileName.c_str(),ios::in);<br>
if
(!fin.is_open())<br>
{<br>
cout<<
"打开文件"
<<infilename<<
"失败。"
<<endl;<br>
exit
(1);<br>
}<br>
<br>
ofstream fout;<br>
fout.open(outFileName.c_str(),ios::out);<br>
if
(!fout.is_open())<br>
{<br>
cout<<
"创建文件"
<<outfilename<<
"失败。"
<<endl;<br>
exit
(1);<br>
}<br>
<br>
string line;<br>
getline(fin,line);<br>
while
(line.length()>0)
{<br>
istrstream ss(line.c_str());<br>
Hero aHero;<br>
ss>>aHero.name>>aHero.age>>aHero.sex>>aHero.weight>>aHero.color;<br>
cout<<ahero.name<<
'\t'
<<ahero.age<<
'\t'
<<ahero.sex<<
'\t'
<<ahero.weight<<
'\t'
<<ahero.color;<br>
fout<<ahero.name<<
'\t'
<<ahero.age<<
'\t'
<<ahero.sex<<
'\t'
<<ahero.weight<<
'\t'
<<ahero.color;<br>
<br>
int
num;<br>
do
<br>
{<br>
ss>>num;<br>
aHero.number.push_back(num);<br>
cout<<
'\t'
<<num;<br>
fout<<
'\t'
<<num;<br>
}
while
(ss.good());<br>
<br>
cout<<endl;<br>
fout<<endl;<br>
heroList.push_back(aHero);<br>
getline(fin,line);<br>
}<br>
<br>
fin.close();<br>
fout.close();<br>
return
0;<br>
}<br>
<br>
</endl;<br></endl;<br></num;<br></num;<br></ahero.name<<
'\t'
<<ahero.age<<
'\t'
<<ahero.sex<<
'\t'
<<ahero.weight<<
'\t'
<<ahero.color;<br></ahero.name<<
'\t'
<<ahero.age<<
'\t'
<<ahero.sex<<
'\t'
<<ahero.weight<<
'\t'
<<ahero.color;<br></outfilename<<
"失败。"
<<endl;<br></infilename<<
"失败。"
<<endl;<br></hero></
int
></vector></string></strstream></fstream></iostream>