C++ String Concatenation Appendix

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.