29 lines
822 B
C++
29 lines
822 B
C++
|
#include <bits/stdc++.h>
|
||
|
|
||
|
using namespace std;
|
||
|
|
||
|
int main()
|
||
|
{
|
||
|
string s1 = "linux c/c++中指针与引用是课程的重点知识";
|
||
|
s1.replace(s1.find('/'), 1, "//");
|
||
|
cout << s1 << endl;
|
||
|
|
||
|
s1.erase(2, 5); // 删除从下标为2开始的5个字符
|
||
|
s1.insert(2, 5, '*'); // 在下标为2的位置插入5个字符*
|
||
|
|
||
|
// s1.replace(2, 5, "*****"); // 从下标为2开始的5个字符替换为5个字符*
|
||
|
// s1.replace(2, 5, "*****", 2, 3); // 从下标为2开始的5个字符替换为从下标为2开始的3个字符
|
||
|
|
||
|
cout << s1 << endl;
|
||
|
|
||
|
string::iterator it = s1.begin();
|
||
|
while (it != s1.end())
|
||
|
{
|
||
|
cout << *it << " "; // 中文字符迭代器无法识别,会输出乱码,因为中文字符 UTF-8 占用3个字节
|
||
|
it++;
|
||
|
}
|
||
|
cout << endl;
|
||
|
|
||
|
return 0;
|
||
|
}
|