In my previous blog post I compared the different ways of concatenating a string in C++. I did however miss one very obvious way to do this. In contrary to Java (where a String is immutable), C++ just offers an append method on a string. In this short blog post I repeat the previous test but now include the append method from string.
The append method only allows appending strings, which means we will need to convert integers and doubles to a string before being able to append it, similar to the regular addition. As a result we see very similar behaviour.
It shouldn’t come really as a surprise that the append function performs very similar to the addition. As a result the conclusion presented in the previous blog post is still relevant.
Whether you want to use regular addition or append is more a type of flavour instead of a real advice. But do note that append is slightly faster than the append methods in all cases.