Question

I read istream::get and a doubt still hangs. Let's say my delimiter is actually the NULL '\0' character, what happens in this case? From what I read:

If the delimiting character is found, it is not extracted from the input sequence and remains as the next character to be extracted. Use getline if you want this character to be extracted (and discarded). The ending null character that signals the end of a c-string is automatically appended at the end of the content stored in s.

The reason I would prefer "get" over "readline" is because of the capability to extract the character stream into a "streambuf".

Was it helpful?

Solution

If you have something like this, then delimiter will not get stuck in the input stream:

std::string read_str(std::istream & in)
{
        const int size  = 1024;
        char pBuffer[size];
        in.getline(pBuffer, size, '\0');
        return std::string(pBuffer);
}

just an example if you have '\0' as delimiter and strings are not bigger than 1024 bytes.

OTHER TIPS

I dont' quite get your problem.

On the msdn website, for the get function, it says:

In all cases, the delimiter is neither extracted from the stream nor returned by the function. The getline function, in contrast, extracts but does not store the delimiter. In all cases, the delimiter is neither extracted from the stream nor returned by the function. The getline function, in contrast, extracts but does not store the delimiter.

http://msdn.microsoft.com/en-us/library/aa277360(VS.60).aspx

I don't think your going to have a problem, since the msdn site tells that the delimiter is neither extracted from the stream, nor returned vy the function.

Or maybe I'm missing a point here?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top