std::strchr
提供: cppreference.com
ヘッダ <cstring> で定義
|
||
const char* strchr( const char* str, int ch ); |
||
char* strchr( char* str, int ch ); |
||
str
の指すバイト文字列内の文字 static_cast<char>(ch) が現れる最初の位置を探します。
終端のヌル文字は文字列の一部であるとみなされ、 '\0' を検索した場合に見つけられます。
目次 |
[編集] 引数
str | - | 解析するヌル終端バイト文字列を指すポインタ |
ch | - | 検索する文字 |
[編集] 戻り値
str
内の見つかった文字を指すポインタ、またはそのような文字が見つからなかった場合はヌルポインタ。
[編集] 例
Run this code
#include <iostream> #include <cstring> int main() { const char *str = "Try not. Do, or do not. There is no try."; char target = 'T'; const char *result = str; while ((result = std::strchr(result, target)) != NULL) { std::cout << "Found '" << target << "' starting at '" << result << "'\n"; // Increment result, otherwise we'll find target at the same location ++result; } }
出力:
Found 'T' starting at 'Try not. Do, or do not. There is no try.' Found 'T' starting at 'There is no try.'
[編集] 関連項目
文字が現れる最初の位置を配列から探します (関数) | |
文字列内の文字を探します ( std::basic_string<CharT,Traits,Allocator> のパブリックメンバ関数)
| |
ワイド文字列中のワイド文字が現れる最後の位置を探します (関数) | |
文字が現れる最後の位置を探します (関数) | |
区切り文字集合の任意の文字が文字列中に現れる最初の位置を探します (関数) | |
strchr の C言語リファレンス
|