length
描述 (Description)
它以字节为单位返回字符串的长度。
声明 (Declaration)
以下是std :: string :: length的声明。
size_t length() const;
C++11
size_t length() const noexcept;
参数 (Parameters)
没有
返回值 (Return Value)
它以字节为单位返回字符串的长度。
异常 (Exceptions)
永远不要抛出任何例外
例子 (Example)
在下面的示例中为std :: string :: length。
#include <iostream>
#include <string>
int main () {
std::string str ("Sairamkrishna Mammahe");
std::cout << "The size of str is " << str.length() << " bytes.\n";
return 0;
}
样本输出应该是这样的 -
The size of str is 21 bytes.