I'm trying to initialize a vector using iterators and I'm getting a compiler error basically saying that there's no matching function to call.
The code reads from a file with an istream_iterator and ends with an input sentinel. Then I try to initialize the vector with those two iterators.
#include "std_lib_facilities.h"
#include<iterator>
int main()
{
string from, to; // get source and target file names
cin >> from >> to;
ifstream is(from.c_str()); // open input stream
ofstream os(to.c_str()); // open output stream
istream_iterator<string> ii(is); // make input iterator for stream
istream_iterator<string> eos; // input sentinel
ostream_iterator<string> oo(os,"\n");
vector<string> words(ii, eos); // vector initialized from input
sort(words.begin(), words.end()); // sort the buffer
copy(words.begin(), words.end(), oo); // copy buffer to output
}
I know I could use the copy function to copy the input stream into the vector, but I read that it can be done this way as well. Can anyone explain why this is not compiling? Thanks.
Compiler error:
C:\Users\Alex\C++\stream_iterators.cpp|16|error: no matching function for call to `Vector<String>::Vector(std::istream_iterator<String, char, std::char_traits<char>, ptrdiff_t>&, std::istream_iterator<String, char, std::char_traits<char>, ptrdiff_t>&)'|
Edit: It is not a header problem. Std_lib_facilities has all of the needed headers.