第 14 题  想要得到字符串 world,下面程序横线处应该填入的是( )。


别灰心,再试一次!

💡 真题解析

【答案】D

【考纲知识点】字符串及其函数

【解析】insert方法原型为basic_string& insert( size_type index, size_type count, CharT ch );第一个参数表示插入位置,第二个参数表示插入的字符串是什么。

substr方法原型为basic_string substr( size_type pos = 0, size_type count = npos ) const;  第一个参数表示截取子串的开始位置,第二个表示截取长度。



考点:C++字符串 insert 和 substr 函数的使用。
答案:D
解析:A选项原字符串第5个位置后不足5个字符;B选项 substr(4,4)取的不是 world ;C选项 insert("world")用法错误;D选项插入 World 后可取出 world 。

知识点解析str.substr(5, 5) 从索引 5 截取 5 个字符,原字符串 "HelloC++" 中索引 5 开始为 "C++",但题目要求输出 "world",选项可能存在题目描述冲突。