If I have a wstringstream
, and I want to get its .str()
data as a LPCWSTR, how can I do that?
views:
89answers:
2or, if assigned to a constant reference, the lifetime of the reference
Greg Domjan
2010-06-07 17:41:32
@Greg: I was just in the process of writing this. `:)`
sbi
2010-06-07 17:44:36
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
2010-06-07 19:47:33
@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
2010-06-07 19:49:35