Quote:Original post by jyk
Quote:...and I tend to try not to use them if I don't need a copy of a string such as const char* in a function call etc.
In such cases you can usually just pass a string object by constant reference. Ta-da! No copy.
(Also, some implementations of std::string are able to avoid unnecessary copies/allocations under certain circumstances, but as this behavior is implementation-dependent it shouldn't really be counted on.)
Exactly. I don't assume that it would it would anyway, so I just ask for a const char* because I
know its only a pointer and I prefer it that way.
std::strings aren't the super holy grail that everyone HAS to use ALL the time. I myself don't throw in a vector<> when all is needed is something like int [4] or use a string when I need a char tmp[32] for any temporary strings writes i may do in a function.
If I need a container then I'll use STL (or my own template containers), otherwise I prefer to keep it small and simple and use native types.