std::basic_string::replace - cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
|
|
(1) | |
|
|
(2) | |
|
|
(3) | |
|
|
(4) | |
|
|
(5) | |
|
|
(6) | (desde C++11) |
Substitui a parte da corda indicado por [pos, pos + count) ou [first, last) com uma nova seqüência.
Original:
Replaces the part of the string indicated by either [pos, pos + count) or [first, last) with a new string.
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
A nova seqüência pode ser um dos seguintes:
Original:
The new string can be one of:
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
1)
str string
Original:
string str
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
2)
substring [pos2, pos2 + count2) de str ou caracteres na [first2, last2) alcance
Original:
substring [pos2, pos2 + count2) of str or characters in the range [first2, last2)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
3)
charcters count2 primeiro da cadeia de caracteres apontada por cstr
Original:
first count2 charcters of the character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
4)
terminada em nulo cadeia de caracteres apontada por cstr
Original:
null-terminated character string pointed to by cstr
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
5)
count2 cópias de ch personagem
Original:
count2 copies of character ch
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
6)
caracteres na ilist lista de inicializador
Original:
characters in the initializer list ilist
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Parâmetros
| pos | - | início da subsequência que vai ser substituído Original: start of the substring that is going to be replaced The text has been machine-translated via Google Translate. |
| count | - | comprimento da subsequência que vai ser substituído Original: length of the substring that is going to be replaced The text has been machine-translated via Google Translate. |
| first, last | - | intervalo de caracteres que vai ser substituído Original: range of characters that is going to be replaced The text has been machine-translated via Google Translate. |
| str | - | string para substituição Original: string to use for replacement The text has been machine-translated via Google Translate. |
| pos2 | - | início da substring para substituir com Original: start of the substring to replace with The text has been machine-translated via Google Translate. |
| count2 | - | número de caracteres para substituir com Original: number of characters to replace with The text has been machine-translated via Google Translate. |
| cstr | - | ponteiro para a cadeia de caracteres a ser usado para substituição Original: pointer to the character string to use for replacement The text has been machine-translated via Google Translate. |
| ch | - | caráter valor a ser usado para a substituição Original: character value to use for replacement The text has been machine-translated via Google Translate. |
| first2, last2 | - | intervalo de caracteres a serem usados para substituição Original: range of characters to use for replacement The text has been machine-translated via Google Translate. |
| init | - | lista de inicializador com os personagens usam para substituição Original: initializer list with the characters to use for replacement The text has been machine-translated via Google Translate. |
| Type requirements | ||
-InputIt must meet the requirements of InputIterator.
| ||
Valor de retorno
*this
Exceções
std::out_of_range if pos > length() or pos2 > str.length()
std::length_error se a string resultante será superior a seqüência de comprimento máximo possível (std::string::npos - 1)
Original:
std::length_error if the resulting string will exceed maximum possible string length (std::string::npos - 1)
The text has been machine-translated via Google Translate.
You can help to correct and verify the translation. Click here for instructions.
Exemplo
#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'; }
Saída:
A quick red fox jumps over the lazy dog.