//string字符存取
void test01() {
string str = "hello";
cout << "str= " << str << endl;
for (int i = 0; i < str.size(); i++) {
cout << str[i] << " ";
}
cout << endl;
for (int i = 0; i < str.size(); i++) {
cout << str.at(i) << " ";
}
cout << endl;
//修改单个字符
str[0] = 'x';
cout << "str= " << str << endl;
str.at(1)='x';
cout << "str= " << str << endl;
}
插入和删除
//字符串的插入和删除
void test01() {
string str = "hello";
str.insert(1, "111");
cout << "str= " << str << endl;
//删除
str.erase(1, 3);
cout << "str= " << str << endl;
}
str.insert(1, "111");
str.erase(1, 3);