Hey everyone,
i want to read in a file that has two parts. The first part is letters and the second part is numbers. They are separated by a blank line.
I'm having trouble actually finding the blank line that separates the two parts of the text file.
So the file format is:
a b c d
e f g h
i j k l
1 2 3
4 5 6
7 8 9
and so forth.
Here's what I'm trying to do
Code:
string t1, t2, t3, t4;
int n1, n2, n3;
int blankFound = 0;
while (!in1.eof()&&(blankFound==0)) { // read first part of file
string s;
getline(in1, s);
if(s.compare("")==0){
blankFound=1;
}
in1 >> t1 >> t2 >> t3 >> t4;
cout << t1 << t2 << t3 << t4 << endl;
}
while(!in1.eof()) { //read second part
in1 >> n1 >> n2 >> n3;
cout << n1 << n2 << n3 << endl;
}
I get the output (I'm missing the first line of the file somewhere!)
efgh
ijlk
123
456
789
My mixing of getline() and the >> operator is probably not good and is not working out.
Anyway I can test for a blank line with >> operator? It just seems to skip ahead and read the next text, and if i do noskipws it just reads every white space which isnt whta i want either.
Any help wud be great,
Cheers!