阅读量:124
在C++中,length()函数通常用于获取字符串的长度,即字符串中字符的数量。这个函数通常用于标准库中的string类,用来获取字符串的长度。示例代码如下:
#include
#include
int main() {
std::string str = "Hello, World!";
int len = str.length();
std::cout << "Length of the string is: " << len class="hljs-keyword">return 0;
}
上面的代码将输出字符串"Hello, World!"的长度,即13。在C++中,字符串的长度通常是以字符的数量来表示,而不包括字符串结尾的空字符。