How to convert String to a WString.
Before can convert the EscapeXML I need to convert first the string to wstring.
Example:
I have a string value = "& & &", then I want to convert this string to wstring.
My Source-Code:
string escapeXML(const std::string & value)
{
// Here
CA2W ca2w(value.c_str());
wstring value = ca2w;
int output_size = EscapeXML(value.c_str(), value.length(), 0, 0, ATL_ESC_FLAG_ATTR);
std::wstring testout;
testout.resize(output_size);
EscapeXML(value.c_str(), value.length(), &testout[0], output_size, ATL_ESC_FLAG_ATTR);
using convert_type = std::codecvt_utf8<wchar_t>;
std::wstring_convert<convert_type, wchar_t> converter;
string converted_str = converter.to_bytes(testout);
return converted_str;
}
int main()
{
std::string test = " & & & ";
cout << escapeXML(test) << '/n';
return 0;
}
My Output:
C2082: redefinition of formal parameter 'value'
IntelliSense: argument of type "const char *" is incompatible with parameter of type "const wchar_t *"