TheDeveloperBlog.com

Home | Contact Us

C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML

C++ String push_back() function

C++ String push_back() function tutorial for beginners and professionals with examples on constructor, if-else, switch, break, continue, comments, arrays, object and class, exception, static, structs, inheritance, aggregation etc.

<< Back to CPP

C++ String push_back()

This function is used to add new character ch at the end of the string, increasing its length by one.

Syntax

Consider a string s1 and character ch . Syntax would be :

s1.push_back(ch);

Parameters

ch : New character which is to be added.

Return value

It does not return any value.

Example 1

Let's see simple example.

#include<iostream>
using namespace std;
            int main()
           {
           string s1 = "Hell";
           cout<< "String is :" <<s1<<'\n';
           s1.push_back('o');
           cout<<"Now, string is :"<<s1;
          return 0;   
           } 

Example 2

Let's consider another simple example.

#include<iostream>
using namespace std;
int main()
{
string str = "java tutorial ";
cout<<"String contains :" <<str<<'\n';
str.push_back('1');
cout<<"Now,string is : "<<str;
return 0; 
}

Output:

String contains :java tutorial
Now,string is java tutorial 1

Example 3

Let's see the example of inserting an element at the end of vector.

#include<iostream>
#include<vector>
using namespace std;
int main()
{
vector<char> s;
s.push_back('j');
s.push_back('a');
s.push_back('v');
s.push_back('a');
for(int i=0;i<s.size();i++)
cout<<s[i];
return 0;
}

Output:

Java

Next TopicC++ Strings




Related Links:


Related Links

Adjectives Ado Ai Android Angular Antonyms Apache Articles Asp Autocad Automata Aws Azure Basic Binary Bitcoin Blockchain C Cassandra Change Coa Computer Control Cpp Create Creating C-Sharp Cyber Daa Data Dbms Deletion Devops Difference Discrete Es6 Ethical Examples Features Firebase Flutter Fs Git Go Hbase History Hive Hiveql How Html Idioms Insertion Installing Ios Java Joomla Js Kafka Kali Laravel Logical Machine Matlab Matrix Mongodb Mysql One Opencv Oracle Ordering Os Pandas Php Pig Pl Postgresql Powershell Prepositions Program Python React Ruby Scala Selecting Selenium Sentence Seo Sharepoint Software Spellings Spotting Spring Sql Sqlite Sqoop Svn Swift Synonyms Talend Testng Types Uml Unity Vbnet Verbal Webdriver What Wpf