std::basic_string::replace — cppreference.com
De cppreference.com
<metanoindex/>
<tbody> </tbody>
|
|
(1) | |
|
|
(2) | |
|
|
(3) | |
|
|
(4) | |
|
|
(5) | |
|
|
(6) | (depuis C++11) |
Remplace la partie de la chaîne signalée par le [pos, pos + count) ou [first, last) par une nouvelle chaîne .
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.
La nouvelle chaîne peuvent être:
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 chaîne
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)
[pos2, pos2 + count2) chaîne de caractères ou str dans le [first2, last2) gamme
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 premiers de la chaîne de caractères pointée par 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)
chaîne de caractères terminée par NULL pointé par 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 copies de ch caractère
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)
caractères dans la liste d'initialisation ilist
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.
Paramètres
| pos | - | le début de la sous-chaîne qui va être remplacé Original: start of the substring that is going to be replaced The text has been machine-translated via Google Translate. |
| count | - | longueur de la chaîne qui va être remplacé Original: length of the substring that is going to be replaced The text has been machine-translated via Google Translate. |
| first, last | - | plage de caractères qui va être remplacé Original: range of characters that is going to be replaced The text has been machine-translated via Google Translate. |
| str | - | chaîne à utiliser pour le remplacement Original: string to use for replacement The text has been machine-translated via Google Translate. |
| pos2 | - | début de la chaîne à remplacer Original: start of the substring to replace with The text has been machine-translated via Google Translate. |
| count2 | - | nombre de caractères de remplacement Original: number of characters to replace with The text has been machine-translated via Google Translate. |
| cstr | - | pointeur vers la chaîne de caractères à utiliser pour le remplacement Original: pointer to the character string to use for replacement The text has been machine-translated via Google Translate. |
| ch | - | caractère de la valeur à utiliser pour le remplacement Original: character value to use for replacement The text has been machine-translated via Google Translate. |
| first2, last2 | - | plage de caractères à utiliser pour le remplacement Original: range of characters to use for replacement The text has been machine-translated via Google Translate. |
| init | - | liste d'initialisation avec les caractères à utiliser pour le remplacement 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.
| ||
Retourne la valeur
*this
Exceptions
std::out_of_range if pos > length() or pos2 > str.length()
std::length_error si la chaîne résultante ne dépasse pas la longueur maximale possible de chaîne (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.
Exemple
#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'; }
Résultat :
A quick red fox jumps over the lazy dog.