当前位置:优学网  >  在线题库

在C中读取文件时重复最后一项++

发表时间:2022-07-26 03:26:21 阅读:81

当遍历条目为int的字符串流并使用带条件的while循环(eof)时,我会重复最后一个元素.代码如下所示:

line = "25 25 64 46 23"

int x;

isstringstream stringTest(line)

while (!stringTest.eof()){

       stringTest >> x;

       cout << "This is x: " << x << endl;

}

我的输出是:"这是x:25"

"这是x:25"

"这是x:64"

"这是x:46"

"这是x:23"

"这是x:23"

有人能解释一下这是怎么发生的吗?有什么办法可以解决这个问题?谢谢你的帮助!

🎖️ 优质答案
相关问题