std::basic_string::replace - cppreference.com
Da cppreference.com.
|
|
Questa pagina è stata tradotta in modo automatico dalla versione in ineglese della wiki usando Google Translate. La traduzione potrebbe contenere errori e termini strani. Muovi il puntatore sopra al testo per vedere la versione originale. Puoi aiutarci a correggere gli gli errori. Per ulteriori istruzioni clicca qui. |
<metanoindex/>
<tbody> </tbody>
|
|
(1) | |
|
|
(2) | |
|
|
(3) | |
|
|
(4) | |
|
|
(5) | |
|
|
(6) | (dal C++11) |
Sostituisce la parte della stringa indicata da una [pos, pos + count) o [first, last) con una nuova stringa.
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 nuova stringa può essere:
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)
stringa str
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)
sottostringa [pos2, pos2 + count2) di str o caratteri nel [first2, last2) gamma
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 prima della stringa di caratteri puntata da 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)
terminazione null stringa di caratteri puntata da 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 copie di ch carattere
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)
personaggi del ilist lista di inizializzazione
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.
Parametri
| pos | - | inizio della sottostringa che sta per essere sostituito Original: start of the substring that is going to be replaced The text has been machine-translated via Google Translate. |
| count | - | lunghezza della sottostringa che sta per essere sostituito Original: length of the substring that is going to be replaced The text has been machine-translated via Google Translate. |
| first, last | - | intervallo di caratteri che sta per essere sostituito Original: range of characters that is going to be replaced The text has been machine-translated via Google Translate. |
| str | - | stringa da utilizzare per la sostituzione Original: string to use for replacement The text has been machine-translated via Google Translate. |
| pos2 | - | inizio della sottostringa da sostituire con Original: start of the substring to replace with The text has been machine-translated via Google Translate. |
| count2 | - | numero di caratteri da sostituire con Original: number of characters to replace with The text has been machine-translated via Google Translate. |
| cstr | - | puntatore alla stringa di caratteri da utilizzare per la sostituzione Original: pointer to the character string to use for replacement The text has been machine-translated via Google Translate. |
| ch | - | carattere di valore da utilizzare per la sostituzione Original: character value to use for replacement The text has been machine-translated via Google Translate. |
| first2, last2 | - | gamma di caratteri da utilizzare per la sostituzione Original: range of characters to use for replacement The text has been machine-translated via Google Translate. |
| init | - | lista di inizializzazione con i caratteri da utilizzare per la sostituzione 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.
| ||
Valore di ritorno
*this
Eccezioni
std::out_of_range if pos > length() or pos2 > str.length()
std::length_error se la stringa risultante supera la lunghezza massima possibile stringa (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.
Esempio
#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.