简体   繁体   English

有没有办法使用 c++ 使用 getline() 访问下一行?

[英]Is there a way to access the next line with getline() with c++?

I am trying to access the next line to check if I would like to change a variable or not.我正在尝试访问下一行以检查是否要更改变量。 Specifically, I want to check if the difference between the current value and the next one is less than a number, if it is not than I would like to assign a different value to a variable, but if it its than I want to retain the value I have now.具体来说,我想检查当前值和下一个值之间的差异是否小于一个数字,如果不是,我想为变量分配一个不同的值,但如果它比我想保留我现在拥有的价值。 My question is, is there a way to "look ahead" with getline(), kind of like an equivalent of i+1 in a for loop.我的问题是,有没有办法使用 getline() 来“向前看”,有点像 for 循环中的 i+1 等价物。

I suggest to defer acting on the first line until the second is parsed.我建议推迟对第一行的操作,直到解析第二行。

Then you can decide whether to use a content from the first line or modify it.然后你可以决定是使用第一行的内容还是修改它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM