#P1068. 字符串专题训练
字符串专题训练
- 在 C++ 中,执行
string s = "CCF-GESP"; cout << s.length();的输出是({{ select(1) }})。
- 7
- 8
- 9
- 10
- 已知
string s = "Hello World";,执行cout << s.find("o");的输出结果是({{ select(2) }})。
- 4
- 7
- 5
- 8
- 已知
string s = "ABCDEF";,则执行s.substr(2, 3)返回的子串是({{ select(3) }})。
- "BCD"
- "CDE"
- "CD"
- "BCDE"
- 执行下列代码后的输出是()。
string s1 = "123", s2 = "456";
cout << s1 + s2;
{{ select(4) }}
- 579
- 123456
- "123+456"
- 运行时错误
- 已知
string s = "apple";,执行s.rfind("p")的返回值(即最后一次出现 'p' 的下标)是({{ select(5) }})。
- 1
- 2
- 5
- 0
- C++ 标准库中的
std::string类型可以通过+运算符直接实现两个字符串对象的拼接。({{ select(6) }})
- 正确
- 错误
- 如果
string s = "abc";,那么访问s[3]会返回字符串的结束符'\0'且不会导致编译错误。({{ select(7) }})
- 正确
- 错误
string类的成员函数substr(1, 3)表示截取并返回从下标 1 开始、连续 3 个字符组成的子串。({{ select(8) }})
- 正确
- 错误
- 当
s.find("x")在字符串s中找不到目标字符时,它会返回一个固定的常量值string::npos。({{ select(9) }})
- 正确
- 错误
- 在 C++ 中,
string s = "Gesp";与string t = "Gesp";可以直接使用==运算符来判断它们的内容是否相等。({{ select(10) }})
- 正确
- 错误