#include <stdio.h>
#include <iostream>
#include <string>
using namespace std;
void main()
{
string str("HELLO");
char ch = 'a';
string::iterator it;
//字符长度
cout << "字符串str的长度是" << str.length() << endl;
//增加字符
it = str.begin() + 2;// 在 string 字符串中第2位 插入 Ch 内容
str.insert(it, ch);
cout << "插入后的字符串是" << str << endl;
//删除字符
str.erase(it, it + 1);
cout << "删除后的字符串是" << str << endl;
getchar();
}
关于string的操作
最新推荐文章于 2021-06-28 10:50:47 发布