C++ string push_back() Function
Example
Add a character to the end of a string:
string txt = "Hello";
txt.push_back('!');
cout << txt;
Definition and Usage
The push_back() function adds one character to the end of a string.
To add more than one character, use append() or the += operator.
The push_back function is defined in the <string> header file.
Syntax
string.push_back(char c);
Parameter Values
| Parameter | Description |
|---|---|
| c | Required. The character to add. Use single quotes, like '!'. |
Technical Details
| Returns: | Nothing (void). |
|---|
Related Pages
Read more about strings in our String Tutorial.