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 : “<< str3 <<endl;

// concatenates str1 and str2

   str3 = str1 + str2;

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

return0;

}

Related Posts

© 2024 Software Engineering - Theme by WPEnjoy · Powered by WordPress