C++ 字串庫 - size



描述

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

宣告

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

size_t size() const;

C++11

 size_t size() const noexcept;

引數

返回值

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

異常

從不丟擲任何異常。

示例

以下是如何使用 std::string::size 的示例。

#include <iostream>
#include <string>

int main () {
   std::string str ("Sairaqmkrishna Mammahe");
   std::cout << "The size of str is " << str.size() << " bytes.\n";
   return 0;
}

示例輸出應如下所示:

The size of str is 22 bytes.
string.htm
廣告