char_traits::find
Vyhledá první výskyt zadaného znaku v zadaném rozsahu znaků.
static const char_type* find(
const char_type* _Str,
size_t _Num,
const char_type& _Ch
);
Parametry
_Str
První znak v řetězci, které mají být prohledány._Num
Počet pozic, počítáno od prvního, v rozsahu, které mají být prohledány._Ch
Znak, který má být vyhledán v rozsahu.
Vrácená hodnota
Ukazatel na první výskyt zadaného znaku v rozsahu, pokud je nalezena shoda, v opačném případě se ukazatel s hodnotou null.
Příklad
// 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;
}
Požadavky
Hlavička: <string>
Obor názvů: std