string push_back() in C++

push_back(): This function append a single character to the given string. 

This function is available in the below file.

File: basic_string.h

Parameters:

 __c – Character to append. 

Syntax:

str.push_back(__c)

For Example:

str = "abc"

str.push_back('d') => This appends character 'd' to the string.

So, string becomes "abcd"

Approach

C++

#include <bits/stdc++.h>
using namespace std;

int main()
{
    string str = "abc";

    str.push_back('d');

    cout << str << "\n";
    

    return 0;
}


No comments:

Post a Comment