所以我的text.txt看起来是这样的:C++文件读取错误
208 84 Sally Goodnow 30:23 52 F Lancaster
209 344 Scott Grady 30:28 42 M Clinton
210 191 gail holland 30:36 52 F worcester
211 43 Karen Hughes 30:45 46 F Shirley
212 221 Edward m Powers Jr. 30:48 60 M Clinton
213 173 Lisa Zancewicz 30:49 34 F Clinton
214 186 Julianne Ryll 30:54 51 F Clinton
215 245 Briana Gibson 30:54 27 F Marlborough
我的代码读取该文件看起来是这样的:
int a;
int b;
string c;
string d;
string e;
string f;
string g;
string h;
string mystr;
int mymin;
int mysec;
int i;
int count=0;
while((infile>>a>>b>>c>>d>>e>>f>>g)&&getline(infile, h))
我的代码只是在突破212线,我想它与Edward m Powers Jr.这个名字有关(现在我真的很讨厌这个名字,每次我看它,大声笑)。这个名字用完了我的四根琴弦,使h = 60M克林顿。是因为字符串h不能存储整数60吗?我不认为这是原因。
我正在做getline(infile,h)因为我不在乎镇上的名字,兰开斯特,克林顿都是镇名。
我试图跳过线212,我做了这样的事情:
string all
while(getline(infile, all)
{
if(all.at[0]!='2'&&all.at[1]!='1'&&all.at[2]!='2')
{
infile>>a>>b>>c>>d>>e>>f>>g;
getline(infile, h);
我这样做只是为了跳过线212,但没有奏效。它只是在其他线路中断。