std::basic_string::substr
Da cppreference.com.
< cpp | string | basic string
![]() | 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. |
basic_string substr( size_type pos =0, size_type count = npos ); | ||
Restituisce una sottostringa
[pos, pos+count)
. Se la sottostringa richiesto dura oltre la fine della stringa, o se count == npos, la sottostringa restituita è [pos, size())
. Original:
Returns a substring
[pos, pos+count)
. If the requested substring lasts past the end of the string, or if count == npos, the returned substring is [pos, size())
. The text has been machine-translated via Google Translate.
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.
Indice |
[modifica]Parametri
pos | - | posizione del primo carattere da includere Original: position of the first character to include The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
count | - | lunghezza della sottostringa Original: length of the substring The text has been machine-translated via Google Translate. You can help to correct and verify the translation. Click here for instructions. |
[modifica]Valore di ritorno
String contenente il
[pos, pos+count)
sottostringa.Original:
String containing the substring
[pos, pos+count)
.The text has been machine-translated via Google Translate.
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.
[modifica]Eccezioni
std::out_of_range if pos > size().
[modifica]Complessità
Lineare in
count
Original:
Linear in
count
The text has been machine-translated via Google Translate.
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.
[modifica]Esempio
#include <string>#include <iostream> int main(){std::string a ="0123456789abcdefghij"; std::string sub1 = a.substr(10);std::cout<< sub1 <<'\n'; std::string sub2 = a.substr(5, 3);std::cout<< sub2 <<'\n'; std::string sub3 = a.substr(12, 100);std::cout<< sub3 <<'\n';}
Output:
abcdefghij 567 cdefghij
[modifica]Vedi anche
copia caratteri (metodo pubblico) |