Modify input stream data on the fly

Posted by Frizi on Stack Overflow See other posts from Stack Overflow or by Frizi
Published on 2014-06-12T20:56:09Z Indexed on 2014/06/12 21:25 UTC
Read the original article Hit count: 164

Filed under:
|

I would like to implement a std::stream modifier/parser, that is doing data manipulation on the fly.

Is it possible to create it in form of stream manipulator? For example, i want to strip all the line comments (from any // to the end of line) out of the stdin and pass it to stdout.

string str;
istream strippingCin = cin >> stripcomments;

while(strippingCin.good())
{
    strippingCin >> str;
    cout << str;
}

There may be also a large file input instead of cin, so i don't want to load full stream data into memory at once.

Is it possible without writing my own stream class?

Maybe is there another route i should take instead?

© Stack Overflow or respective owner

Related posts about c++

Related posts about iostream