作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个文件,我想存储一行的第一部分直到到达“,”,然后将该行的剩余部分存储到另一个变量中。目前,它跳过了一半的行。例如,这是我的文件的三行:
021200725340,Scotch Removable Clear Mounting Squares - 35 Ct
041520035646,Careone Family Comb Set - 8 Ct
204040000000,Plums Black
我的代码只存储了一半的行:
while(getline(file, upc)){
getline(file, upc, ',');
getline(file, description);
}
最佳答案
My code only stores half of the lines:
在 while
语句的条件内调用 getline
负责此操作。
将您的代码更改为:
while( getline(file, upc, ',') && getline(file, description) )
{
// Use the data.
}
关于c++ - 如何在 C++ 的同一行上两次 getline()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58897675/
我是一名优秀的程序员,十分优秀!