std::string::push_back() in C++ Read Courses Practice Improve Improve Improve Like Article Like Save Article Save Report issue Report The push_back() member function is provided to append characters. Appends character c to the end of the string, increasing its length by one. Syntax : void string:: push_back (char c) Parameters: Character which to be appended. Return value: None Time Complexity: O(1) as it appends a single character to the string. Auxiliary Space: O(1) Error: throws length_error if the resulting size exceeds the maximum number of characters(max_size). CPP // CPP code for to illustrate // std::string::push_back() #include <iostream> #include <string> using namespace std; // Function to demonstrate push_back() void push_backDemo(string str1, string str2) { // Appends character by character str2 // at the end of str1 for(int i = 0; str2[i] != '\0'; i++) { str1.push_back(str2[i]); } cout << "After push_back : "; cout << str1; } // Driver code int main() { string str1("Geeksfor"); string str2("Geeks"); cout << "Original String : " << str1 << endl; push_backDemo(str1, str2); return 0; } Output Original String : Geeksfor After push_back : GeeksforGeeks If you like GeeksforGeeks(We know you do!) and would like to contribute, you can also write an article using write.geeksforgeeks.org or mail your article to review-team@geeksforgeeks.org. Learn to code easily with our course Coding for Everyone. This course is accessible and designed for everyone, even if you're new to coding. Start today and join millions on a journey to improve your skills!Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now! Commit to GfG's Three-90 Challenge! Purchase a course, complete 90% in 90 days, and save 90% cost click here to explore. Last Updated : 27 Feb, 2023 Like Article Save Article Previous std::string::replace() in C++ Next std::string::append vs std::string::push_back() vs Operator += in C++ Share your thoughts in the comments Add Your Comment Please Login to comment...