最終更新日時:
が更新

履歴 編集

function
<cwchar>

std::wcschr

namespace std {
  const wchar_t* wcschr(const wchar_t* s, wchar_t c); // (1)
  wchar_t* wcschr(wchar_t* s, wchar_t c);            // (2)
}

概要

ワイド文字列から文字を検索する。

戻り値

sが指す文字列の中で最初に現れるcを指すポインタを返す。見つからない場合はヌルポインタを返す。

終端のヌル文字も検索の対象となる。

備考

  • C++では、引数のconst性を保った結果を返すために、2つのオーバーロードとして宣言される
  • この関数は、C++26からフリースタンディング処理系でも使用できる

#include <cwchar>
#include <iostream>

int main()
{
  const wchar_t* s = L"hello";
  const wchar_t* p = std::wcschr(s, L'l');

  std::wcout << (p - s) << std::endl;
  std::wcout << p << std::endl;
}

出力

2
llo

バージョン

言語

  • C++98

関連項目

参照