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

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

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

function
<string>

std::basic_string::end

iterator end();                      // (1) C++98
iterator end() noexcept;             // (1) C++11
constexpr iterator end() noexcept;   // (1) C++20

const_iterator end() const;                    // (2) C++98
const_iterator end() const noexcept;           // (2) C++11
constexpr const_iterator end() const noexcept; // (2) C++20

概要

末尾の次を指すイテレータを取得する。

戻り値

末尾の次を指すイテレータ

例外

投げない

備考

  • basic_stringクラスのイテレータ範囲は、ヌル文字('\0')終端ではない
  • この関数によって返されるイテレータは、*thisが保持するいずれの要素も参照しない。その指す先は、不正な範囲となるだろう

例

#include <iostream>
#include <string>
#include <algorithm>

int main()
{
  std::string s = "hello";
  s.insert(s.begin() + 2, '\0');

  // 文字列オブジェクトsに含まれる、ヌル文字を除く全ての要素を出力
  std::for_each(s.begin(), s.end(), [](char c) {
    if (c != '\0')
      std::cout << c << std::endl;
  });
}

出力

h
e
l
l
o

参照

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