c++ 字符串比较

对std::string 直接用 ==

对char* 应该用strcmp()

    string t1 = "helloWorld";
    string t2 = "helloWorld";
 
    if (t1 == t2)
    {
        printf("***t1 ,t2 是一样的\n");
        printf("这是正确的\n");
    }
 
    if (t1.c_str() == t2.c_str())
    {
        printf("@@@t1 ,t2 是一样的\n");
    }
    
    if (strcmp(t1.c_str(),t2.c_str()) == 0)
    {
        printf("###t1 ,t2 是一样的\n");
        printf("这是正确的\n");
    }
--------------------- 
作者:wisdom605768292 
来源:CSDN 
原文:https://blog.csdn.net/wisdom605768292/article/details/12076375 
版权声明:本文为博主原创文章,转载请附上博文链接!    

猜你喜欢

转载自www.cnblogs.com/zealousness/p/10140189.html
今日推荐