char_traits::find
文字の範囲の指定された文字の最初のオカレンスを検索します。
static const char_type* find(
const char_type* _Str,
size_t _Num,
const char_type& _Ch
);
パラメーター
_Str
検索文字列の最初の文字。_Num
先頭からカウント検索する範囲の位置の数。_Ch
スコープ内で検索する文字。
戻り値
一致が見つかった場合は、指定した範囲の最初の文字へのポインター; 生成 それ以外の場合は、null ポインター。
使用例
// char_traits_find.cpp
// compile with: /EHsc
#include <string>
#include <iostream>
int main( )
{
using namespace std;
const char* s1 = "f2d-1234-abcd";
const char* result1;
cout << "The string to be searched is: " << s1 << endl;
// Searching for a 'd' in the first 6 positions of string s1
result1 = char_traits<char>::find ( s1 , 6 , 'd');
cout << "The character searched for in s1 is: "
<< *result1 << endl;
cout << "The string beginning with the first occurrence\n "
<< "of the character 'd' is: " << result1 << endl;
// When no match is found the NULL value is returned
const char* result2;
result2 = char_traits<char>::find ( s1 , 3 , 'a');
if ( result2 == NULL )
cout << "The result2 of the search is NULL." << endl;
else
cout << "The result2 of the search is: " << result1
<< endl;
}
必要条件
ヘッダー: <string>
名前空間: std