Search code examples
c++stlfunctoristream

How to create a functor that will read next value from input stream?


Something like this :

std::bind1st(std::mem_fun(&istream::get ??), cin). This does not seem to work for me.

EDIT:

Use :

vector<int> vNumbers;
generate_n(back_inserter(vNumbers), iNumCount, functor);

Solution

  • I don't think the standard binding functions let you define nullary functions. bind1st binds to the first argument of a binary function and returns a unary function that passes its parameter as the second parameter of the bound function.

    You can go outside the standard library, however, and use Boost.Bind:

    boost::bind(&istream::get, &cin)