std::strstr - cppreference.com
提供: cppreference.com
<tbody> </tbody>
| ヘッダ |
||
|
|
||
|
|
||
str の指すバイト文字列内のバイト文字列 target が現れる最初の位置を探します。 終端のヌル文字は比較されません。
引数
| str | - | 調べるヌル終端バイト文字列を指すポインタ |
| target | - | 検索するヌル終端バイト文字列を指すポインタ |
戻り値
str 内の見つかった部分文字列の最初の文字を指すポインタ、またはそのような文字が見つからない場合は NULL。 target が空文字列を指す場合は、 str が返されます。
例
#include <iostream> #include <cstring> int main() { const char *str = "Try not. Do, or do not. There is no try."; const char *target = "not"; const char *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.'