📄 stringdemo.cpp
字号:
#include <iostream>
#include <string>
using namespace std;
int main()
{
string s = "I sing the body electric";
cout << s << endl;
cout << s.substr(2,4) << endl;
cout << s.substr(s.find("electric")-5) << endl << endl;
string copy(s);
int bodyPos = copy.find("body");
copy.replace(bodyPos,copy.length(),"blues");
cout << copy << endl << endl;
cout << "search for chars/strings" << endl;
cout << "first e at " << s.find('e') << endl;
cout << "last e at " << s.rfind('e') << endl;
cout << "first z at " << s.find('z') << endl;
cout << "space after body " << s.find(" ", bodyPos) << endl;
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -