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

string::compare的更多相关文章

  1. C# CompareTo 和 String.Compare

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...

  2. 1,字符是否为空,2,比较两个字符大小。String.Compare(String, String)。string.IsNullOrEmpty(string)

    1, String.Compare 方法 (String, String) 比较两个指定的 String 对象. 值 条件 小于零 strA 小于 strB. 零 strA 等于 strB. 大于零 ...

  3. 深入解析字符串的比较方法:“==”操作符;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。

    1:要判断2个字符串变量是否相等,最高效的方法是看它们是否指向相同的内存地址.前面使用RefernceEquals方法来比较.如果2个变量指向的是不同的内存地址,那么就需要逐字符的比较2个字符串的变量 ...

  4. C# 字符串比较大小 string.Compare()方法

    string.Compare方法,用来比较2个字符串值得大小 string.Compare(str1, str2, true); 返回值: 1 : str1大于str2 0 : str1等于str2 ...

  5. C#基础知识之字符串比较方法:“==”操作符;RefernceEquals;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。

    一.“==”操作符:String.Equals:ReferenceEquals 方法 1.在编程中实际上我们只需要这两种比较,c#中类型也就这两种 (1)值类型的比较:一般我们就是判断两个值类型实例各 ...

  6. String.Compare 方法 (String, Int32, String, Int32, Int32)

    String.Compare 方法 (String, Int32, String, Int32, Int32) 对两个指定的 String 对象的子字符串进行比较,并返回一个指示二者在排序顺序中的相对 ...

  7. C# string.Compare()

    tring.Compare方法,用来比较2个字符串值得大小 string.Compare(str1, str2, true); 返回值: 1 : str1大于str2 0 : str1等于str2 - ...

  8. 【Leetcode_easy】844. Backspace String Compare

    problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...

  9. 844. Backspace String Compare

    class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...

  10. STL || HDU 1894 String Compare

    如果一个词包含再另一个词的前面(前缀),是一对前缀,求一共有多少对 *解法:STL万岁 #include<string>:https://www.cnblogs.com/SZxiaochu ...

随机推荐

  1. 分类并查集[noi2001 食物链]

    题目链接:http://cogs.pro:8081/cogs/problem/problem.php?pid=pxNJzxVPU 题目有三种动物,A吃B,B吃C,C吃A 即B是A的食物,A是B的天敌, ...

  2. 【机器学习】QQ-plot深入理解与实现

    QQ-plot深入理解与实现 26JUN June 26, 2013 最近在看关于CSI(Channel State Information)相关的论文,发现论文中用到了QQ-plot.Sigh!我承 ...

  3. Coloring Edges(有向图环染色)-- Educational Codeforces Round 72 (Rated for Div. 2)

    题意:https://codeforc.es/contest/1217/problem/D 给你一个有向图,要求一个循环里不能有相同颜色的边,问你最小要几种颜色染色,怎么染色? 思路: 如果没有环,那 ...

  4. 【hash表】图书管理

    [哈希和哈希表]图书管理 题目描述 图书管理是一件十分繁杂的工作,在一个图书馆中每天都会有许多新书加入.为了更方便的管理图书(以便于帮助想要借书的客人快速查找他们是否有他们所需要的书),我们需要设计一 ...

  5. gridview单元格编辑添加数据

    行号 private void gridView1_CustomDrawRowIndicator(object sender, DevExpress.XtraGrid.Views.Grid.RowIn ...

  6. JQuery --- 第六期 (Ajax)

    欢迎访问我的个人博客,获取更多有用的东西 链接一 链接二 也可以关注我的微信订阅号:CN丶Moti 点击查看Ajax

  7. CSS3总结二:(background)背景/渐变色函数

    background-color(CSS2) background-image background-position background-size background-repeat backgr ...

  8. EF Code First 数据迁移操作

    打开执行命令窗体 1.EF Code First创建数据库 PM> Install-Package EntityFramework 2.EF Code First数据库迁移 2.1.生成数据库 ...

  9. fastadmin中关联表时A为主表,想让B表和C表关联时怎么办?

    $sql = Db::connect('数据库')->table('C表')->where('status', 'normal')->field('字段 别称[不可与其他表重复]') ...

  10. 【异常】Phoenix异常:java.lang.ArithmeticException: Rounding necessary

    1 异常sql upsert into WMBIGDATA.ODS_ES_CHARGING_STATION(id,evcosType,address,serviceTel,supportOrder,o ...