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;

}

posted @ 2025-04-09 20:18  lalalandla  阅读(8)  评论(0)    收藏  举报