Longueur de chaîne C++
Longueur de chaine
Pour obtenir la longueur d'une chaîne, utilisez la length()
fonction :
Exemple
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.length();
Conseil : Vous pouvez voir certains programmes C++ qui utilisent la size()
fonction pour obtenir la longueur d'une chaîne. Ceci est juste un alias de length()
. C'est à vous de décider si vous souhaitez utiliser length()
ou size()
:
Exemple
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.size();