作业介绍

笔记-string函数

int main() {
	string s = "abcdbcbcbc";
	cout << s.find("bc") << endl; //查询字符串中有没有出现bc这个子串
	cout << s.find("bc",4) << endl; //从下标4开始查找 
	//如果出现了,返回第一次出现的下标
	//如果没出现,返回-1(如果输出会显示奇怪的数字) 
	s.replace(2,4,"hyx"); //从下标2开始连续4个字符替换成其余字符串 
	cout << s <<endl; 
	s.replace(2,4,10,'h');//从下标2开始连续4个字符替换成连续10个字符h
	cout << s << endl;
	
	s.insert(2,"hyx"); //在下标2的位置插入指定字符串 
	cout << s << endl; 
	s.insert(2,5,'h'); //在下标2的位置插入5个h
	cout << s << endl;
	
	s.erase(2,5); 
	cout << s << endl; //从下标2开始删除连续5个字符
	s.erase(2); //删除下标2开始后面所有字符
	cout << s << endl; 

    s.length();  //获取s的长度
	
	return 0;
}

状态
已结束
题目
7
开始时间
2024-3-29 0:00
截止时间
2024-4-6 23:59
可延期
24 小时