#string002. string类型的成员函数2

string类型的成员函数2

string类型的成员函数2

一、填空题1

​ 现有一字符串s如代码所示,根据代码完成第1题-第11题,假设题目中的代码互相独立,互不影响。从A~F的文字描述中,选择合适的描述填入代码后面空格,答案需要大写,不要填入无关的空格。

代码如下:

string s="AAHello AA world";

1.s.size():{{ input(1) }}

2.s.find("AA"):{{ input(2) }}

3.s.find("XX"):{{ input(3) }}

4.s.find("AA",s.find("AA")+2):{{ input(4) }}

5.s.substr(2,5):{{ input(5) }}

6.s.substr(11):{{ input(6) }}

7.s.erase(8,3):{{ input(7) }}

8.s.erase(7):{{ input(8) }}

9.s.replace(0,2,""):{{ input(9) }}

10.s.replace(8,2,2,'K'):{{ input(10) }}

11.s.insert(10,"BB"):{{ input(11) }}

12.[非成员函数] getline(cin,s):{{ input(12) }}

代码功能描述如下:

A. 删除从下标 7 开始到末尾的所有字符,s 变为 "AAHello"

B. 从下标 2 开始查找子串 "AA",返回其第一次出现的位置,即 7

C. 在下标 10 处插入字符串 "BB",s 变为 "AAHello AABB world"

D. 返回从下标 11 开始到末尾的子串,即 "world"

E. 从标准输入读取一整行(包括空格)并赋值给 s,覆盖 s 原来的内容

F. 返回字符串 s 的长度(字符个数),即 15

G. 将从下标 8 开始的 2 个字符替换为 2 个字符 'K',s 变为 "AAHello KK world"

H. 删除从下标 8 开始的 3 个字符,s 变为 "AAHello world"

I. 返回子串 "AA" 第一次出现的位置(下标),即 0

J. 返回从下标 2 开始、长度为 5 的子串,即 "Hello"

K. 将从下标 0 开始的 2 个字符替换为空串,即删除开头的 "AA",s 变为 "Hello AA world"

L. 查找子串 "XX",未找到,返回 string::npos