Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Something like istream::getline() but with alternative delim characters?

What's the cleanest way of getting the effect of istream::getline(string, 256, '\n' OR ';')?

I know it's quite straightforward to write a loop, but I feel that I might be missing something. Am I?

What I used:

while ((is.peek() != '\n') && (is.peek() != ';'))
    stringstream.put(is.get());
like image 659
Erika Avatar asked Oct 15 '12 07:10

Erika


1 Answers

Unfortunately there is no way to have multiple "line endings". What you can do is read the line with e.g. std::getline and put it in an std::istringstream and use std::getline (with the ';' separator) in a loop on the istringstream.

Although you could check the Boost iostreams library to see it it has functionality for it.

like image 133
Some programmer dude Avatar answered Nov 15 '22 09:11

Some programmer dude