是否有一个标志使 istream 仅将制表符视为分隔符?
我想让 istream 仅将制表符视为空白。因此,给定“{json : 5}\tblah”,我想将 json 加载到 obj1
中,并将“blah”加载到 obj2
中,代码如下:
is << obj1 << obj2
有没有办法在不将对象加载到字符串中的情况下执行此操作?
I want to make istream
consider only tabs as whitespace. So, given "{json : 5}\tblah", I want to load json into obj1
and "blah" into obj2
with code like the following:
is << obj1 << obj2
Is there a way to do this without loading the objects into strings?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,在本地集中,制表符是唯一具有空格属性的字符。
困难的部分:创建一个继承自
ctype
的 Facet。然后确保将所有字符设置为非空格(制表符除外)。简单的部分:创建一个使用构面的区域设置对象并将其注入流:
结果:
注意:甚至连换行符都不是上面的空白字符。因此,运算符
>>
将读取行尾并忽略它。Yep in the local set the tab is the only character that has the space attribute.
The hard part: Create a facet that inherits from
ctype
. Then make sure you set all characters to be not whitespace (except tab).The easy part: create a locale object that uses the facet and imbue the stream with it:
The result:
Note: Not even newline is not a whitespace character above. So the operator
>>
will read across the end of line and ignore it.std::getline
怎么样?What about
std::getline
?