这是我的代码,我不明白为什么get(char)
给我错误的结果!
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;
我预计输出将是:
d
(因为第一个getline
存储"0 TS1"
in line
,然后第二个getline
存储"paris"
in line
,然后我们将指针向前移动 3 个字符,使其位于 the"n"
和"d"
of之间london
)。
但我实际上有:
米
顺便说一句,这是我的文件:
0 TS1
paris
london
amsterdam
1 TC2
xxxxx
yyyyy
zzzzz
我在 Windows 10 上使用代码块,并在 Windows 上使用记事本创建了我的文件。