std::basic_string::replace
![]() |
This page has been machine-translated from the English version of the wiki using Google Translate.
The translation may contain errors and awkward wording. Hover over text to see the original version. You can help to fix errors and improve the translation. For instructions click here. |
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.You can help to correct and verify the translation. Click here for instructions.
You can help to correct and verify the translation. Click here for instructions.
str
str
You can help to correct and verify the translation. Click here for instructions.
[pos2, pos2 + count2)
str
或字符的范围内[first2, last2)
[pos2, pos2 + count2)
of str
or characters in the range [first2, last2)
You can help to correct and verify the translation. Click here for instructions.
count2
charcters指向的字符串的第一cstr
count2
charcters of the character string pointed to by cstr
You can help to correct and verify the translation. Click here for instructions.
cstr
cstr
You can help to correct and verify the translation. Click here for instructions.
count2
份的性格ch
count2
copies of character ch
You can help to correct and verify the translation. Click here for instructions.
ilist
的字符数ilist
You can help to correct and verify the translation. Click here for instructions.
目录 |
[编辑] 参数
pos | - | 开始,将要被替换的子串
Original: start of the substring that is going to be replaced The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count | - | 的子串的长度,将要被替换
Original: length of the substring that is going to be replaced The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
first, last | - | 是将要被替换的字符的范围
Original: range of characters that is going to be replaced The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
str | - | 字符串,用于更换
Original: string to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
pos2 | - | 开始的子串替换
Original: start of the substring to replace with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count2 | - | 数目的字符来代替
Original: number of characters to replace with The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
cstr | - | 要使用的字符串替换指针
Original: pointer to the character string to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
ch | - | 更换使用的字符值
Original: character value to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
first2, last2 | - | 更换使用的字符范围
Original: range of characters to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
init | - | 初始化列表中要使用的字符替换
Original: initializer list with the characters to use for replacement The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
Type requirements | ||
-InputIt must meet the requirements of InputIterator .
|
[编辑] 返回值
*this
[编辑] 例外
std::out_of_range if pos > length()
or pos2 > str.length()
std::string::npos - 1
)std::string::npos - 1
)You can help to correct and verify the translation. Click here for instructions.
[编辑] 为例
#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'; }
Output:
A quick red fox jumps over the lazy dog.