How can I read from an std::istream (using operator>>)?

Posted by dehmann on Stack Overflow See other posts from Stack Overflow or by dehmann
Published on 2009-08-19T22:31:50Z Indexed on 2010/04/08 3:33 UTC
Read the original article Hit count: 369

How can I read from an std::istream using operator>>?

I tried the following:

void foo(const std::istream& in) {
  std::string tmp;
  while(in >> tmp) {
     std::cout << tmp;
  }
}

But it gives an error:

error: no match for 'operator>>' in 'in >> tmp'

© Stack Overflow or respective owner

Related posts about c++

Related posts about operators