The use of c++ fstream and getline.
迷茫
迷茫 2017-05-16 13:27:58
0
1
579
ifstream input(s);
input>>V;
input>>E;
string text;
while(getline(input,text))
{
    cout<<text<<endl;
}
``

代码就是这样,那个s是文件路径,txt文件如下:
11
5
0 5
4 3
0 1
9 12
6 4
5 4

就是这样的数字,中间没有空行。读的时候,11 和5 确实读进V和E了,但是在0 5之前却读入了一个空行。
本来这中间是没有空行的。请问这是为什么?往上搜了也没找到答案。谢谢大家。
迷茫
迷茫

业精于勤,荒于嬉;行成于思,毁于随。

reply all(1)
Ty80

Is it because I input>>E, and then the input is an "n" at this time, and getline reads the line break after element 5 in the second line?

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!