📅  最后修改于: 2020-09-25 09:10:01             🧑  作者: Mango
size_t strcspn( const char *dest, const char *src );
如果src
或dest
都未指向终止的空字节字符串,则strcspn()
函数的行为未定义。
它在
strcspn()
函数在src
首次出现的任何字符之前返回dest
的字符数。
#include
#include
using namespace std;
int main()
{
char num[] = "0123456789";
char code[] = "ceQasieoLPqa4xz10Iyq";
size_t result = strcspn(code, num);
if (result < strlen(code))
cout << "First occurrence of number in " << code << " is at position " << result;
else
cout << code << " does not contain numbers";
return 0;
}
运行该程序时,输出为:
First occurrence of number in ceQasieoLPqa4xz10Iyq is at position 12