zoukankan      html  css  js  c++  java
  • c++ 字符串比较

    对std::string 直接用 ==

    对char* 应该用strcmp()

        string t1 = "helloWorld";
        string t2 = "helloWorld";
     
        if (t1 == t2)
        {
            printf("***t1 ,t2 是一样的
    ");
            printf("这是正确的
    ");
        }
     
        if (t1.c_str() == t2.c_str())
        {
            printf("@@@t1 ,t2 是一样的
    ");
        }
        
        if (strcmp(t1.c_str(),t2.c_str()) == 0)
        {
            printf("###t1 ,t2 是一样的
    ");
            printf("这是正确的
    ");
        }
    --------------------- 
    作者:wisdom605768292 
    来源:CSDN 
    原文:https://blog.csdn.net/wisdom605768292/article/details/12076375 
    版权声明:本文为博主原创文章,转载请附上博文链接!    
  • 相关阅读:
    自我介绍
    币值转换
    打印沙漏
    对我影响最大的三位老师

    pta
    pta-3
    学习计划
    对我有影响的三个老师
    介绍自己
  • 原文地址:https://www.cnblogs.com/zealousness/p/10140189.html
Copyright © 2011-2022 走看看