zoukankan      html  css  js  c++  java
  • c++ string compare

    #include <iostream>
    #include <string>

    using namespace std;

    int main()
    {
      string str1("hello");
      string str2("hello");
      string str3("world");

      if (str1 != str2)
      {
        cout << "str1 不等于 str2" << endl;
      }

      if (str1 == str2)
      {
        cout << "str1 等于 str2" << endl;
      }

      if (str1>str3)
      {
        cout << "str1 大于 str3" << endl;
      }
      else
      {
        cout << "str1不大于str3" << endl;
      }

      if (str1.compare(str3)>0)
      {
        cout << "str1 大于 str3" << endl;
      }

      if (str1.compare(str3)<0)
      {
        cout << "str1 小于 str3" << endl;
      }

      if (str1.compare(str3)==0)
      {
        cout << "str1 等于 str3" << endl;
      }

      string str4(str3,2,3);
      cout << str4 << endl;
      if (str1.compare(str4)>0)
      {
        cout << "str1 大于 str4" << endl;
      }
      else
      {
        cout << "str1 不等于于 str4" << endl;
      }

      if (str1.compare(2,2,str2)>0)
      {
        cout << "str1 大于 str2" << endl;
      }

      system("pause");
      return 0;
    }

    =================================

    str1 等于 str2
    str1不大于str3
    str1 小于 str3
    rld
    str1 不等于于 str4
    str1 大于 str2
    请按任意键继续. . .

  • 相关阅读:
    mysql 中索引的限制
    lvm扩展记录
    转载:权威GIS类数据网站汇总
    转载:文件系统inodes使用率过高问题处理
    转载: k8s--pod的状态为evicted
    转载:k8s更新策略
    转载:Tomcat的JVM内存溢出解决方法
    软件推荐
    U盘安装Centos7 问题记录
    转载:Linux下查找文件
  • 原文地址:https://www.cnblogs.com/herd/p/10995961.html
Copyright © 2011-2022 走看看