How to initialize an std::string using ""?
Posted
by
Mohsin
on Stack Overflow
See other posts from Stack Overflow
or by Mohsin
Published on 2011-03-18T15:20:34Z
Indexed on
2011/03/18
16:10 UTC
Read the original article
Hit count: 258
I'm facing problems with initializing a std::string variable using ""
(i.e. an empty string). It's causing strange behavior in code that was previously working. Is the following statement wrong?
std::string operationalReason = "";
When I use the following code everything works fine:
std::string operationalReason;
operationalReason.clear();
I believe that string literals are stored in a separate memory location that is compiler-dependent. Could the problem I'm seeing actually be indicating a corruption of that storage? If so, it would get hidden by my usage of the clear()
function.
Thanks.
© Stack Overflow or respective owner