Question

After binding cin to istream_iterator and reading its I don't have whitespaces:

iter = istream_iterator<char>(std::cin);
istream_iterator<char> iend;
for(int i=0;i<maxBufferSize;++i)
{
    if(iter==iend)
      return STREAMBUFFER_EOF;
    c = *iter;
    buffer += c;
    iter++;
}
if(iter==iend)
  return STREAMBUFFER_EOF;
return STREAMBUFFER_OK;

Is there way to configure it to not ignore whitespaces?

Was it helpful?

Solution

If your goal is to read unformatted character data from the stream, you could use std::istreambuf_iterator instead, without needing to change any format flags of the stream.

std::istreambuf_iterator<char> iter(std::cin), iend;
for(int i=0;i<maxBufferSize;++i)
...

OTHER TIPS

Sorry answer is very simple, before binding cin to iterator you have to use manipulator noskipws:

std::cin>>noskipws;
iter = istream_iterator<char>(std::cin);

Now it's working.

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