开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜