📅  最后修改于: 2020-09-25 09:07:24             🧑  作者: Mango
const char* strchr( const char* str, int ch );
char* strchr( char* str, int ch );
strchr()
函数采用两个参数: str
和ch
。它在str
指向的字符串搜索字符 ch
。
它在
如果找到了字符 ,则strchr()
函数将返回一个指向str
字符位置的指针,否则返回空指针。
#include
#include
using namespace std;
int main()
{
char str[] = "Programming is easy.";
char ch = 'r';
if (strchr(str, ch))
cout << ch << " is present \"" << str << "\"";
else
cout << ch << " is not present \"" << str << "\"";
return 0;
}
运行该程序时,输出为:
r is present "Programming is easy."