c++中length函数的有哪些作用
在C++中,length()函数通经常使用于获得字符串的长度,即字符串中字符的数量。这个函数通经常使用于标准库中的string类,用来获得字符串的长度。示例代码以下:
#include <iostream>
#include <string>
int main() {
std::string str = "Hello, World!";
int len = str.length();
std::cout << "Length of the string is: " << len << std::endl;
return 0;
}
上面的代码将输出字符串"Hello, World!"的长度,即13。在C++中,字符串的长度通常是以字符的数量来表示,而不包括字符串结尾的空字符。
TOP