strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。该函数是二进制安全的。
包含文件:string.h
函数名: strstr
函数原型:extern char *strstr(const char *str1, const char *str2);
语法:* strstr(str1,str2)
str1: 被查找目标 string expression to search.
str2: 要查找对象 The string expression to find.
返回值:该函数返回str2第一次在str1中的位置,如果没有找到,返回NULL
The strstr() function returns the ordinal position within str1 of the first occurrence of str2. If str2 is not found in str1, strstr() returns 0.
例子:
|
1 2 3 |
charstr[]="1234xyz"; char*str1=strstr(str,"34"); cout<<str1<<endl; |
显示: 34 xyz
浙公网安备 33010602011771号