I'm trying to print a xml to a file using rapidxml
.
But the values are in wstring
. So i've used templated version of it by attaching
xml_node wchar_t
instead of specialization of the xml_node .
But When i'm doing this:
std::string xml_as_string;
rapidxml::print<std::string,wchar_t>(std::back_inserter(xml_as_string), doc); ///i'm not very sure of this line . This line only gives a error
// i tried this "rapidxml::print<t>" also i'm getting an error .
//Save to file
std::ofstream file_stored("C:\\Logs\\file_stored.xml");
file_stored << doc;
file_stored.close();
doc.clear();
It throws a error stating Error:
error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'rapidxml::xml_document<Ch>' (or there is no acceptable conversion).
Any help will be appreciated . thanks
If you need to explicitly specify the template arguments here:
you almost certainly make a mistake. The function is supposed to work with the help of automatic template arg detection like this.
The point is that both args have to be wchar_t based otherwise the templated function would not match. So in the first step you may only output to an
wstring
orstd::basic_string<wchar_t>
to be more specific. Or to an output iterator into a wchar_t output.If you want to end up with a char based encoding (e.g utf8) you may either use a wchar file output stream and imbue(...) it like:
or you may use some iconv(...) based solution. You may of course us a file output iterator directly on the wofstream.