-->

2/27/21

How to append char to end of string in C++ || Best way to append char to end of string

 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? 
Let's see

Method -1 

+= operator

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.
How to append char to end of string in C++ || Best way to append char to end of string



Method 2-

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.





Advertiser

all right reserved @technicalkeeda.in. Powered by Blogger.