所以我的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,但沒有奏效。它只是在其他線路中斷。