Why use append for strings?


whats wrong with:

std::string st;

st="";
st+="dfjsdjfls";
st+="dfjklsjdfl";

std::cout <<st;

as opposed to using the append method? Is there a memory hole above somehow?

I was just wondering why it is there :/
Last edited on
append is the same as += for either a string or char* argument, but append has other forms and is therefore more versatile. From the reference at this site:

1
2
3
4
5
6
7
string& append ( const string& str );
string& append ( const string& str, size_t pos, size_t n );
string& append ( const char* s, size_t n );
string& append ( const char* s );
string& append ( size_t n, char c );
template <class InputIterator>
   string& append ( InputIterator first, InputIterator last );
Ok thats good, i was wondering if it worked like C# where it creates a new string each time (although it nulls the old for GC is actually not as good as using string.format) I wondered if it was the same here.
Topic archived. No new replies allowed.