c++ - Add char to a std::string -
i append char std::string in c++. can think of @ least 3 ways it:
std::string s = "hello"; char c = '!'; s += c; s.append(c); s.push_back(c); - which 1 considered best practice ?
- is there performance difference (c++11) ?
also, if want add 2 strings, same question with:
std::string s1 = "hello ", s2 = "world"; s1.append(s2); s1 += s2;
the question matter of compiler , personal taste and/or company coding style requirements. on loaded operator resolves 2nd choice.
i go first 1 myself
Comments
Post a Comment