C++: Best way to copy a section of WCHAR[] into a wstringstream?
I have a WCHAR[]
, a wstringstream
, and an arbitrary section of the WCHAR[]
that I want to copy into the wstringstream
. What is the best way to do this?
It seems that there must be a better way than this:
for (int开发者_如何学运维 i = start; i < start + length; i++)
{
wszStringStream << wchr[i];
}
Sure. Try this:
wszStringStream.write(wchr+start, length);
std::copy(wchr, wchr + length, std::istream_iterator<WCHAR>(wszStringStream))
should do the trick.
精彩评论