In this quick article, we’ll explore various methods to append a char at the end of a string in C++.

1. Using push_back() function

The recommended approach is to use the standard push_back() function, which is overloaded for chars and appends a character to the string’s end.

Download  Run Code

2. Using += operator

We can also use the string::operator+=, which is overloaded for chars and internally calls to the push_back() function.

Download  Run Code

3. Using append() function

Another plausible approach is to use the append() function to append a single copy of a character at the end of the string, as demonstrated below:

Download  Run Code

4. Using std::stringstream function

Another good alternative is to use a string stream to convert between strings and other numerical types.

Download  Run Code

5. Using insert() function

Finally, we can also use the insert() function to insert a single copy of a character at the specified position in the string.

Download  Run Code

That’s all about appending a char to the end of a string in C++.