Hello there, I am pretty new to c++.
I am trying to read an input file (.txt) with mixed format. However, I have to ignore some lines, such as those lines with "----------" and "OUT", For an example, the .txt file about scores :
Andy 5 Kaliroy 6
Tom 4 Timmy 3
-------------
Sam 2 Darius 6
Sam OUT
Pat 3 Eddie 4
-------------
Timmy OUT
Vic 3 Connie 1
Duke 0 Jake 0
-------------
Dave 3 Kevin 0
Kevin OUT
In turn, I want to save only the names and scores of both players in the arrays, while ignoring or skipping "-----------" and the line with "OUT". Which means I only want these data without changing the original .txt file:
Andy 5 Kaliroy 6
Tom 4 Timmy 3
Sam 2 Darius 6
Pat 3 Eddie 4
Vic 3 Connie 1
Duke 0 Jake 0
Dave 3 Kevin 0
This is my attempt that compiles with no error, but when I cout the saved arrays, nothing happened.
Note a is a struct.
Both Names are string type. Scores are int type.
1 2 3 4 5 6 7 8 9 10 11 12
|
while (!fin.eof()) {
infileB >> a[i].Name1
>> a[i].S1
>> a[i].Name2
>> a[i].S2;
if(a[i].Name1 == "-------------") {
continue;
}
else {
i++
}
}
|
I tried to search for a solution, but cant find any. Thank you!