C++ 字符串长度
字符串长度
要获取字符串的长度,请使用length()函数:
实例
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.length();
运行实例 »
提示: 您可能会看到一些使用size()函数获取字符串长度的C++程序。
这只是length()函数的别名。何时使用length()或size(),则完全由您决定:
实例
string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
cout << "The length of the txt
string is: " << txt.size();
运行实例 »

