String使用
include
include
include
using namespace std;
int main() {
string str = "Hello, c++";
//使用push_back()在字符串末尾添加字符
str.push_back('!');
cout << "string:" << str << endl;
//使用pop_back()移除字符串末尾的字符
str.pop_back();
cout << "string:" << str << endl;
//使用insert()在指定位置插入字符串
str.insert(7, "world,");
cout << str << endl;
//使用+拼接两个String
str = str + "Welcome to programing.";
cout << "string is:" << str << endl;
//获取并打印字符串大小
cout << "Size:" << str.size() << endl;
return 0;
}

浙公网安备 33010602011771号