GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::basic_string::size - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. string
  3. basic_string
  4. size

最終更新日時: 2026年08月27日 14時02分35秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<string>

std::basic_string::size

size_type size() const;                    // (1) C++98
size_type size() const noexcept;           // (1) C++11
constexpr size_type size() const noexcept; // (1) C++20

概要

文字列の長さを取得する。

戻り値

現在格納されている文字列の要素数。

※文字数ではないことに注意

例外

投げない

計算量

定数時間

備考

この関数は、length()メンバ関数と同じ効果を持つ。size()はコンテナインタフェースのために用意されているものだが、どちらを使用してもよい。

例

#include <iostream>
#include <string>

int main()
{
  std::string s = "hello";

  std::size_t n = s.size();
  std::cout << n << std::endl;
}

出力

5

参照

  • LWG Issue 876. basic_string access operations should give stronger guarantees
    • C++11で、例外を送出しないことが規定された
  • P0980R1 Making std::string constexpr
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.