std::memchr
STD::memchr
Defined in header | | |
---|---|---|
const void* memchr( const void* ptr, int ch, std::size_t count | | |
void* memchr( void* ptr, int ch, std::size_t count | | |
皈依ch
到unsigned char
,并在初始值中定位该值的第一次出现。count
字符%28解释为unsigned char
所指对象的%29ptr
...
参数
ptr | - | pointer to the object to be examined |
---|---|---|
ch | - | character to search for |
count | - | number of characters to examine |
返回值
指向字符位置的指针,或NULL
如果找不到这样的角色。
例
搜索一组字符。
二次
#include <iostream>
#include <cstring>
int main()
{
char arr[] = {'a','\0','a','A','a','a','A','a'};
char *pc = (char*)std::memchr(arr,'A',sizeof arr
if (pc != NULL)
std::cout << "search character found\n";
else
std::cout << "search character not found\n";
}
二次
产出:
二次
search character found
二次
另见
strchr | finds the first occurrence of a character (function) |
---|---|
findfind_iffind_if_not (C++11) | finds the first element satisfying specific criteria (function template) |
c备忘录文件
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。