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

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

最終更新日時: 2026年07月22日 16時08分23秒 (JST)
rotarymars が更新

履歴 編集

function
<string>

std::basic_string::starts_with(C++20)

constexpr bool
  starts_with(std::basic_string_view<charT, traits> x) const noexcept; // (1) C++20
constexpr bool
  starts_with(charT x) const noexcept;                                 // (2) C++20
constexpr
  bool starts_with(const charT* x) const;                              // (3) C++20

概要

指定の文字列で始まるかを判定する。

  • (1) : *thisが保持する文字列の先頭が、xが参照する文字列範囲と一致するかを判定する
  • (2) : *thisが保持する文字列の先頭が、文字xと一致するかを判定する
  • (3) : *thisが保持する文字列の先頭が、文字列xと一致するかを判定する

戻り値

以下と等価である:

return std::basic_string_view<charT, traits>(data(), size()).starts_with(x);

例外

  • (1), (2) : 投げない

例

#include <cassert>
#include <string>
#include <string_view>

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

  // (1)
  {
    std::string_view sv = "aaa";
    assert(s.starts_with(sv));
  }

  // (2)
  {
    assert(s.starts_with('a'));
  }

  // (3)
  {
    assert(s.starts_with("aaa"));
  }
}

出力

バージョン

言語

  • C++20

処理系

  • Clang: 7.0 ✅
  • GCC: 9.1 ✅
  • Visual C++: 2019 update 1 ✅

参照

  • P0457R2 String Prefix and Suffix Checking
  • 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.