Comprimento da String C++
Comprimento da string
Para obter o comprimento de uma string, use a length()
função:
Exemplo
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.length();
Dica: Você pode ver alguns programas C++ que usam a size()
função para obter o comprimento de uma string. Este é apenas um alias de length()
. Depende completamente de você se você deseja usar length()
ou size()
:
Exemplo
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.size();