Computer Science Canada [C++] String Composing Tip |
Author: | wtd [ Tue Mar 16, 2004 8:50 pm ] | ||||
Post subject: | [C++] String Composing Tip | ||||
For composing long strings the temptation is to use the std::string class and its + operator. However, this results in a temporary std::string object being created each time the operator is used. Sometimes compilers can optimize this away, but it shouldn't be counted on. Instead use the std::stringstream class.
The same way you should use operator overloading to handle output, you can overload it to handle interactions with std::stringstream.
|