两个连续的换行符作为分隔符 - C/C++
我正在下面编写一个 getline 函数,但我希望分隔字符是两个连续的换行符,这样函数一旦到达空白行就停止读取。
in.getline(temp, 127, delimiter);
可以用 getline 来做到这一点吗?
I'm writing a getline function below but I want the delimiting character to be two consecutive newline characters such the function stops reading once it reaches a blank line.
in.getline(temp, 127, delimiter);
Is it possible to do this with getline?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,但是一个
simple(不像我一开始想象的那么简单)循环就可以做到。No, but a
simple(not quite as simple as I thought at first) loop will do it.istream::getline
的分隔符必须是单个字符。但是,您始终可以自己缓冲结果,检查下一个字符(peek
)以查看其是否为换行符。Delimiter must be a single character for
istream::getline
. However, you could always buffer the result yourself, checking the next character (peek
) to see if its a newline.