C++ 字串庫 - length



描述

它返回字串的長度(以位元組為單位)。

宣告

以下是 std::string::length 的宣告。

size_t length() const;

C++11

size_t length() const noexcept;

引數

返回值

它返回字串的長度(以位元組為單位)。

異常

從不丟擲任何異常。

示例

以下是 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.
string.htm
廣告