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?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top