This isn't so much a specific question about RapidXML convention as it is a question about using a std::vector's constructor.
In all examples that I have found of others using RapidXML, everyone always reads data into a vector of char
's using the std::vector
's constructor like so:
vector<char> buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
There must be a reason for this because when I try to change it to a vector of std::string
's I get a screen full of errors with this being the first error:
error: invalid conversion from ‘void*’ to ‘std::istreambuf_iterator<std::basic_string<char> >::streambuf_type* {aka std::basic_streambuf<std::basic_string<char>, std::char_traits<std::basic_string<char> > >*}’
Is there a way to use std::string and if not why?
What are you trying to do?
Do you want the contents of the file in a single string? If so, then
string buffer((istreambuf_iterator<char>(theFile)), istreambuf_iterator<char>());
should do it.
On the other hand, if you want a vector of strings, with each string containing a single line from the file, you'll have to write a loop like this (untested code):
vector <string> lines;
for (string aLine; std::getline(theFile, aLine) ; )
lines.push_back(aLine);