views:

89

answers:

2

If I have a wstringstream, and I want to get its .str() data as a LPCWSTR, how can I do that?

+1  A: 

wstringstream.str().c_str();

DeadMG
+4  A: 
sbi
or, if assigned to a constant reference, the lifetime of the reference
Greg Domjan
@Greg: I was just in the process of writing this. `:)`
sbi
I think your second code is not fine, because C++ can destroy the temporary before `f` gets called. This really happened to me once! So you must never store the result of `c_str()` or `data()`.
Philipp
@Philipp: It's not legal for the temporary to be destroyed until the end of the evaluation of the full expression so you must have been using a buggy compiler if this happened to you.
Charles Bailey