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
関連項目
wcsrchr: 後方から検索するwcsstr: 部分文字列を検索するstd::strchr(): マルチバイト文字列版
参照
- P2338R4 Freestanding Library: Character primitives and the C library
- C++26で、この関数がフリースタンディング処理系で使用可能になった