How to append char to end of string in C++ || Best way to append char to end of string-
There are 2 ways mention below to append char to the end of string in c++.
But do you know which one is the best way?
we can use += use to append char at the end of the string but by using this method it makes a copy of the initial string and take O(length of the string ) time to make a copy of a string.
Push back method by using this method we do not create any copy of original string we only put char to the and of the string so the time complexity of this function is o(1). Obviously, push back is a better method to append char at the end of the string.