Skip to content
Mon, Oct 12, 2026 / Ideas for a clearer worldINDEPENDENT INSIGHTS · PRACTICAL TOOLS · EXPLAINERS
Sign in
C++ Programming / August 13, 2021

C++ Strings

C++ provides following two types of string representations: The C-style character string as follows: char greeting[6]={‘H’,’e’,’l’,’l’,’o’,’\0′}; The standard C++ library provides a string class type that supports all the operations mentioned above, additionally much more functionality. Following is the example: #include<iostream> #include<string> usingnamespacestd; int main () { string str1 =”Hello”; string str2 =”World”; string str3; // copy str1 into str3    str3 = str1; cout<<“str3 […]

C++ provides following two types of string representations:

The C-style character string as follows:

char greeting[6]={‘H’,’e’,’l’,’l’,’o’,’\0′};

The standard C++ library provides a string class type that supports all the operations mentioned above, additionally much more functionality. Following is the example:

#include<iostream>

#include<string>

usingnamespacestd;

int main ()

{

string str1 =”Hello”;

string str2 =”World”;

string str3;

// copy str1 into str3

   str3 = str1;

cout<<“str3 : “<< str3 <<endl;

// concatenates str1 and str2

   str3 = str1 + str2;

cout<<“str1 + str2 : “<< str3 <<endl;

return0;

}