tags:

views:

45

answers:

2

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];
}
A: 
std::copy(wchr, wchr + length, std::istream_iterator<WCHAR>(wszStringStream))

should do the trick.

jalf
Shouldn't that start at wchr+start?
Owen S.
+1  A: 

Sure. Try this:

wszStringStream.write(wchr+start, length);
Owen S.
yeah, that works nicely.
Rosarch