流中的内联忽略 [英] Inline ignore in Streams

查看:89
本文介绍了流中的内联忽略的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以忽略C ++内联中的字符?

Is there a way to ignore characters in C++ inline?

例如,在此答案中,我正在阅读:

For example in this answer I'm reading in:

istringstream foo("2000-13-30");

foo >> year;
foo.ignore();
foo >> month;
foo.ignore();
foo >> day;

但是我希望能够全部内联:

But I'd like to be able to do this all inline:

foo >> year >> ignore() >> month >> ignore() >> day;

我认为这在C ++中是可能的,但是对于我来说绝对不是编译器.也许我还记得另一种语言?

I thought this was possible in C++, but it definitely isn't compiling for me. Perhaps I'm remembering another language?

推荐答案

foo.ignore()是成员函数,因此不能用作操纵器.它也没有正确的返回类型和参数声明以用作一体.您可以轻松地自己制作:

foo.ignore() is a member function so it can't be used as a manipulator. It also doesn't have the correct return type and parameter declaration to be usable as one. You can easily make your own though:

std::istream& skip(std::istream& is) {
    return (is >> std::ws).ignore();
}

foo >> year >> skip >> month >> skip  >> day;

这篇关于流中的内联忽略的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆