How can I use std::copy to read directly from a file stream to a container?
问题 I ran across a cool STL example that uses istream_iterators to copy from std input (cin) to a vector. vector<string> col1; copy(istream_iterator<string>(cin), istream_iterator<string>(), back_inserter(col)); How would I do something similar to read from a file-stream directly into a container? Let's just say its a simple file with contents: "The quick brown fox jumped over the lazy dogs." I want each word to be a separate element in the vector after the copy line. 回答1: Replace cin with file