Lunghezza della stringa C++
Lunghezza della corda
Per ottenere la lunghezza di una stringa, utilizzare la length()
funzione:
Esempio
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.length();
Suggerimento: potresti vedere alcuni programmi C++ che utilizzano la size()
funzione per ottenere la lunghezza di una stringa. Questo è solo uno pseudonimo di length()
. Sta a te decidere se vuoi usare length()
o size()
:
Esempio
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.size();