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;
    }

  • 相关阅读:
    Scoket简介
    AOP
    Windows服务
    Nginx 教程 (1):基本概念
    异步编程
    并发编程
    常用排序
    序列化
    MSBuild/Projectjson
    不汇报是职场发展的绊脚石
  • 原文地址:https://www.cnblogs.com/xpylovely/p/12069122.html
Copyright © 2011-2022 走看看