typedef std::istream_iterator in;
in(...) is the same as
std::istream_iterator(...): it's calling the constructor for that type. There is a 1-argument constructor which accepts a
std::istream, creating an iterator that represents the current point in that stream; and a 0-argument constructor creating an iterator that represents the end of any given stream. So
std::for_each will iterate over every value provided by
std::cin from now until it runs out.
std::istream_iterator takes a stream and provides an iterator over the
ints in the stream, using
operator>> to read them out of the stream.
I don't know how you could possibly fail. I put
std::istream_iterator into Google and the first result was http://www.sgi.com/tech/stl/istream_iterator.html which is pretty thorough, assuming you're already familiar with iterators. The next result is http://www.cplusplus.com/reference/std/iterator/istream_iterator/ which makes another attempt to explain things and is also fully detailed. Next comes http://stdcxx.apache.org/doc/stdlibref/istream-iterator.html , similarly, which finally explicitly mentions
operator>> instead of just talking about formatted I/O operations (which is what
operator>> does). Next comes a page with some C++ example snippets, then a couple of StackOverflow questions where people were trying to do something similar, etc....