Erika Erika -4 years ago 178
C++ Question

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() != ';'))

Answer Source

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.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download