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

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

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

履歴 編集

function
<string_view>

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

constexpr const_pointer data() const noexcept;

概要

文字配列表現を取得する。

戻り値

*thisが保持している、参照している文字配列へのポインタを返す。

例外

投げない

備考

文字列長はsubstr()メンバ関数やコンストラクタなどで変更できるが、それらは参照の範囲を限定するのみである。この関数によって返される文字配列へのポインタは、参照範囲の終端にヌル文字は挿入しないので注意すること。

例

#include <iostream>
#include <string_view>

int main()
{
  std::string_view sv = "Hello World";
  const char* s = sv.data();
  std::cout << "a : " << s << std::endl;

  // 部分文字列
  std::string_view sv2 = sv.substr(0, 5);
  const char* s2 = sv2.data();
  std::cout << "b : " << sv2 << std::endl;
  std::cout << "c : " << s2 << std::endl; // 参照位置から全体が出力される
}

出力

a : Hello World
b : Hello
c : Hello World

バージョン

言語

  • 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.