实例 C++ 字符串长度

x
 
#include <iostream>
#include <string>
using namespace std;
int main() {
  string txt = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  cout << "The length of the txt string is: " << txt.length();
  return 0;
}
                    

输出结果

The length of the txt string is: 26