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