J
Javier
Hello,
in which cases is it better the use of "const char*" to "string" (or
even const string &).
I mean, in STL (http://www.sgi.com/tech/stl/hash_map.html) I see:
hash_map<const char*, int, hash<const char*>, eqstr> months;
months["january"] = 31;
I think it is for the use in calls like function("my string"), but, is
it really necessary to define funcion(const char*) besides
function(const string &) in my public member functions?
I have read that the compiler does too much temporaries variables in
such cases, but is it true?
And what about in:
string mystring = "my string" + string1 + " is " + string2;
or in:
cout << string << " hello" << string2 << " my name is " << string3;
Thanks.
in which cases is it better the use of "const char*" to "string" (or
even const string &).
I mean, in STL (http://www.sgi.com/tech/stl/hash_map.html) I see:
hash_map<const char*, int, hash<const char*>, eqstr> months;
months["january"] = 31;
I think it is for the use in calls like function("my string"), but, is
it really necessary to define funcion(const char*) besides
function(const string &) in my public member functions?
I have read that the compiler does too much temporaries variables in
such cases, but is it true?
And what about in:
string mystring = "my string" + string1 + " is " + string2;
or in:
cout << string << " hello" << string2 << " my name is " << string3;
Thanks.