C++ language introduction 16– String class
The C++ standard library provides the string class type to support all of the above operations
#include <iostream>
#include <string>
using namespace std;
int main (a)
{
string str1 = "Hello";
string str2 = "World";
string str3;
int len ;
// copy str1 to str3
str3 = str1;
cout << "str3 : " << str3 << endl;
// connect str1 and str2
str3 = str1 + str2;
cout << "str1 + str2 : " << str3 << endl;
// The total length of str3 after connection
len = str3.size(a); cout <<"str3.size() : " << len << endl;
return 0;
}
Copy the code
Operation results: