char* 字符串操作

1.查找子字符串

#include
#include

int main()
{
    char a[] = "abcddabc";
    char b[] = "dda";
    int j;
    string str1(a);
    string str2(b);
    //方法一
    int i = str1.find(str2);  //返回即子字符串索引3
    //方法二
    char *rel = strstr(a, b); //首次出现地址,strstr保存的是ddabc
    if (rel != NULL)
        j = rel -a;         //根据返回子字符串匹配结果输出索引位

    return 0;
}

2.字符串比较

strcmp(fileDir.name, ".") == 0 //相等时成立

你可能感兴趣的:(char* 字符串操作)