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_view::length - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. string_view
  3. basic_string_view
  4. length

最終更新日時: 2026年09月11日 13時06分31秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<string_view>

std::basic_string_view::length(C++17)

constexpr size_type length() const noexcept;

概要

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

戻り値

保持している文字列の長さを返す。

例外

投げない

例

#include <cassert>
#include <iostream>
#include <string_view>

int main()
{
  std::string_view sv1{"Hello World"};
  std::string_view sv2 = sv1.substr(0, 5);

  assert(sv1.length() == 11);
  assert(sv2.length() == 5);

  std::cout << '[' << sv1 << ']' << std::endl;
  std::cout << '[' << sv2 << ']' << std::endl;
}

出力

[Hello World]
[Hello]

バージョン

言語

  • C++17

処理系

  • Clang: 4.0 ✅
  • GCC: 7.1 ✅
  • Visual C++: ??
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.