std::basic_string::replace
|
|
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
| basic_string& replace( size_type pos, size_type count, const basic_string& str ); |
(1) | |
| basic_string& replace( size_type pos, size_type count, const basic_string& str, |
(2) | |
| basic_string& replace( size_type pos, size_type count, const CharT* cstr, size_type count2 ); |
(3) | |
| basic_string& replace( size_type pos, size_type count, const CharT* cstr ); |
(4) | |
| basic_string& replace( size_type pos, size_type count, size_type count2, CharT ch ); |
(5) | |
| basic_string& replace( const_iterator first, const_iterator last, std::initializer_list<CharT> ilist ); |
(6) | (C++11 起) |
[pos, pos + count)或[first, last)一个新的字符串表示的字符串替换的部分.[pos, pos + count) or [first, last) with a new string.str[pos2, pos2 + count2)str或字符的范围内[first2, last2)[pos2, pos2 + count2) of str or characters in the range [first2, last2)count2charcters指向的字符串的第一cstrcount2 charcters of the character string pointed to by cstrcstrcstrcount2份的性格chilist的字符数ilist目录 |
[编辑] 参数
| pos | - | 开始,将要被替换的子串
原文: start of the substring that is going to be replaced |
| count | - | 的子串的长度,将要被替换
原文: length of the substring that is going to be replaced |
| first, last | - | 是将要被替换的字符的范围
原文: range of characters that is going to be replaced |
| str | - | 字符串,用于更换
|
| pos2 | - | 开始的子串替换
原文: start of the substring to replace with |
| count2 | - | 数目的字符来代替
原文: number of characters to replace with |
| cstr | - | 要使用的字符串替换指针
原文: pointer to the character string to use for replacement |
| ch | - | 更换使用的字符值
原文: character value to use for replacement |
| first2, last2 | - | 更换使用的字符范围
原文: range of characters to use for replacement |
| init | - | 初始化列表中要使用的字符替换
原文: initializer list with the characters to use for replacement |
| 类型要求 | ||
-InputIt 必须满足 InputIterator 的要求。
| ||
[编辑] 返回值
*this
[编辑] 例外
std::out_of_range if pos > length() or pos2 > str.length()
std::string::npos - 1)std::string::npos - 1)[编辑] 示例
#include <iostream> #include <string> int main() { std::string str("The quick brown fox jumps over the lazy dog."); str.replace(10, 5, "red"); // (4) str.replace(str.begin(), str.begin() + 3, 1, 'A'); // (5) std::cout << str << '\n'; }
输出:
A quick red fox jumps over the lazy dog.