question about std::string and map

question about std::string and map

Post by tom_usene » Sat, 24 Jan 2004 16:08:32


On Fri, 23 Jan 2004 13:57:00 +0200, "lallous" < XXXX@XXXXX.COM >



Right - std::string always has its own copy, or at least behaves as if
it does.


Yes, that is fine, as long as p and p1 point to valid null-terminated
strings.


That would be more efficient, since the former causes a temporary
string to be constructed.

Tom

C++ FAQ: http://www.yqcomputer.com/ ++-faq-lite/
C FAQ: http://www.yqcomputer.com/ ~scs/C-faq/top.html
 
 
 

question about std::string and map

Post by lallou » Sat, 24 Jan 2004 20:57:00

Hello,

I have:

std::map<std::string, std::string> m;
std::string s1;
char *p = "hello world", *p1 = "value";
a] s1 = p;

is (a) okay if I later set "p = NULL" ? s1 would have its own copy of the
string now?

b] m[p] = p1;
Is that okay? will that create a valid entry into the map?
Or should I use: map[s1] = "value"; ?