#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int main()
{
/*
1.定义一个空字符串
2.定义一个字符串,使用两种不同的方法,将字符串初始化 “#####”
3.获取字符串s长度
4.使用成员函数获取s是否为空
5.向s中index处插入count个字符ch
6.在s中从pos处开始找字符串str,返回str的位置
7.获取s中【pos,pos+n】范围内的子串
8.获取s中第5个字符
9.连接字符串s1和s2
*/
string s;
string s1("#####");//定义并且赋值1
string s2( 5, '#');
cout << s2;
cout << s2.size() << s2.length();
cout << s.empty() << s2.empty() << endl;
s1.insert(1, 4, 'a');
cout << s1 <<endl;
cout << (int)string :: npos << endl;
cout << (int)s1.find( "aa" ,5) <<endl;
cout << s1.substr(4 , 3) << s1.substr(0, 3) <<endl;
cout << s1.substr(5) <<endl;
cout << s1.at(3)<< s1[3] << endl;
s1 += s2;
cout << s1 ;
return 0;
}
—— 本文来自火龙信奥(义乌睿码科技):义乌青少年信息学奥赛与编程教育平台,专注 CSP-J/S、NOIP、GESP 竞赛培训,线上线下融合教学,助力编程升学。网址:hlcoding.com