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

    1. compare 

    string (1)
    4int compare (const string& str) const noexcept;
    
    substrings (2)
    int compare (size_t pos, size_t len, const string& str) const;
    int compare (size_t pos, size_t len, const string& str,
                 size_t subpos, size_t sublen) const;
    
    c-string (3)
    int compare (const char* s) const;
    int compare (size_t pos, size_t len, const char* s) const;
    
    buffer (4)
    int compare (size_t pos, size_t len, const char* s, size_t n) const;

    #include <string>
    #include <iostream>
    using namespace std;
    int main()
    {
    size_t pos = 7;
    size_t len = 3;

    string s1("she is zhh");
    string s2("zhh");
    string s3("i love zhh");
    const char *s4 = "zhh";
    const char *s5 = "i love zhh";
    cout << s1.compare(s2) << endl;
    cout << s1.compare(pos, len, s2) << endl;
    cout << s1.compare(pos ,len, s3, pos, len) << endl;
    cout << s2.compare(s4) << endl;
    cout << s1.compare(pos, len, s4) << endl;
    cout << s1.compare(pos, len, s4, len) << endl;//最后一个参数莫名奇妙???
    try
    {
    s1.compare(20, 100, s2);
    }
    catch(out_of_range)
    {
    cout << "out of range" << endl;
    }
    cout << "no exception" << endl;
    return 0;
    }

  • 相关阅读:
    stm32ADC+DMA串口发送实验
    凑算式
    全排列
    字符串相同
    判断值相同
    插入加号求最小值
    动态规划递归—最小子段和
    动态规划-最小子段和
    进程的描述和进程的创建
    系统调用下
  • 原文地址:https://www.cnblogs.com/xpylovely/p/12069122.html
Copyright © 2011-2022 走看看