I have the following code:
std::istream_iterator<std::string> eos;
std::istream_iterator<std::string> iit (File);
std::vector<std::string> result;
std::copy(iit,eos,std::back_inserter(result));
for(auto it=result.begin(); it!=result.end(); ++it )
std::cout << *it << std::endl;
I am using iterators to read the contents of a File
and store the result to my vector, I don't want to use any while
or for
loop, I want to do it using only any STL
function, so I tried copy
. The contents of the file is in the following form:
Pork bone:4
Pigs trotters:4
Loin of pork:4
The problem is that previous code reads each line until space or new line character, so my vector looks like:
Pork
bone:4
Pigs
trotters:4
Loin
of
pork:4
I want each line to be a new element in my vector, any idea how to solve this?