c++ string 字符串长度函数
时间: 2023-08-03 08:07:27 浏览: 119
C++中可以使用std::string
类来表示字符串,并使用length()
函数来获取字符串的长度。以下是一个示例代码:
#include <iostream>
#include <string>
int main() {
std::string str = "Hello, world!";
int length = str.length();
std::cout << "The length of the string is: " << length << std::endl;
return 0;
}
运行以上代码,将输出字符串的长度为:13。
相关推荐














