C++ tutorial-String Manipulation

C++ String Manipulation

In C++, there are many functions that can be used to manipulate string objects. In this topic we will discussion some C++ string manipulation functions such as size(), assign(), append(), insert(), compare(), erase(), find(), replace(), substr(), and empty().

C++ size() function

C++ provides the size(string) function to count the number of characters in a string object. This function accepts a string argument that you want to count its characters and returns the number of characters count.


#include <cstdlib>
#include <iostream>
#include <conio.h>

using namespace std;

void strmanip(){

  string str="C++ programming code";
  cout<<"The number of characters in the string is:"<<size(str);


int main(){

  return 0;



This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.