Quick links
Latest articles
Internship
Members
New...
Algorithms
Discrete Mathematics
Big data
Languages
C
C++
C++ STL
Java
Data Structure
C#.Net
Android
Kotlin
SQL
Web
PHP
Python
JavaScript
CSS
Ajax
Node.js
Web prog.
Programs
C
C++
DS
Java
C#
Python
Aptitude
C
C++
Java
DBMS
Interview
C
Embedded C
Java
SEO
HR
CS Subjects
CS Basics
O.S.
Networks
DBMS
Embedded Systems
Cloud Computing
Machine learning
CS Organizations
Linux
DOS
More...
Articles
Puzzles
News/Updates

Home » C++ STL

Appending text to the string using string::append() function in C++ STL



C++ STL: string::append() function with example: In this tutorial, we will learn to append text to the string using string::append() function.
Submitted by IncludeHelp, on July 02, 2018

append() is a library function of <string> header, it is used to append the extra characters/text in the string.

Syntax:

string& append(const string& substr);

Here,

  • string& is the reference to the string in which we are adding the extra characters.
  • substr is the extra set of character/sub-string to be appended.

There are some other variations (function overloading) of the function that are going to be used in the program.

Program:

#include <iostream>
#include <string>
using namespace std;

int main ()
{
	string str = "Hello";
	string str2 = " ## ";
	string str3 = "www.google.com";

	cout<<str<<endl;

	//append text at the end 
	str.append (" world");
	cout<<str<<endl;

	//append 'str2'
	str.append (str2) ;
	cout<<str<<endl;

	//append space 
	str.append (" ");
	//append 'google' from str3
	str.append (str3.begin () +4, str3.begin () +10) ;

	cout<<str<<endl;

	return 0;
}

Output

    Hello
    Hello world
    Hello world ## 
    Hello world ##  google





Quick links:
C FAQ(s) C Advance programs C/C++ Tips & Tricks Puzzles JavaScript CSS Python Linux Commands PHP Android Articles More...

Featured post:
Introduction to Linux (Its modes, Safety, Most popular Applications)
Linux Best Distribution Software (Distros) of 2018

Was this page helpful? Please share with your friends...

Are you a blogger? Join our Blogging forum.

Comments and Discussions



Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing » Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates


© https://www.includehelp.com (2015-2018), Some rights reserved.