#P1068. 字符串专题训练

字符串专题训练

  1. 在 C++ 中,执行 string s = "CCF-GESP"; cout << s.length(); 的输出是({{ select(1) }})。
  • 7
  • 8
  • 9
  • 10
  1. 已知 string s = "Hello World";,执行 cout << s.find("o"); 的输出结果是({{ select(2) }})。
  • 4
  • 7
  • 5
  • 8
  1. 已知 string s = "ABCDEF";,则执行 s.substr(2, 3) 返回的子串是({{ select(3) }})。
  • "BCD"
  • "CDE"
  • "CD"
  • "BCDE"
  1. 执行下列代码后的输出是()。
string s1 = "123", s2 = "456";
cout << s1 + s2;

{{ select(4) }}

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