recoba78
recoba78

Reputation: 99

how can i use file.get(char ) after getline()?

Here is my code, I don't understand why the get(char) give me the wrong result !

ifstream uploadFile("upload.txt");
string line;
getline(uploadFile,line);
getline(uploadFile,line);
uploadFile.seekg(3,ios::cur);
char lettre;
uploadFile.get(lettre);
cout << "we get the letter : " << lettre << endl;

i was expected that the output will be:

d

(because the first getline store the "0 TS1" in line, then the second getline store "paris" in line, then we move the pointer 3 chars ahead so it will be between the "n" and the "d" of london).

but I actually have:

m

btw here is my file:

0 TS1  
paris  
london  
amsterdam      

1 TC2  
xxxxx  
yyyyy  
zzzzz

I'm using codeblocks on Windows 10, and I created my file with Notepad on Windows.

Upvotes: 1

Views: 48

Answers (0)

Related Questions