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?

Était-ce utile?

La 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)
...

Autres conseils

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.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top