Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

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.



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.







This post first appeared on Technical Keeda, please read the originial post: here

Share the post

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

×

Subscribe to Technical Keeda

Get updates delivered right to your inbox!

Thank you for your subscription

×