If I have a wstringstream, and I want to get its .str() data as a LPCWSTR, how can I do that?
If I have a wstringstream , and I want to get its .str() data
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can do
wstringstream.str().c_str()as DeadMG writes. However, the result of that call is only valid until the end of lifetime of the expression, this is part of.Specifically, this
will not work, because
wstringstream.str()returns a temporary object and.c_str()returns a pointer into that object, and at the end of the assignment that temporary object will be destructed.What you can do instead is either
or
because temporary objects bound to a
constreference will have their lifetime extended for the reference’s lifetime.