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; |
| c-string (3) |
int compare (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的更多相关文章
- C# CompareTo 和 String.Compare
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- 1,字符是否为空,2,比较两个字符大小。String.Compare(String, String)。string.IsNullOrEmpty(string)
1, String.Compare 方法 (String, String) 比较两个指定的 String 对象. 值 条件 小于零 strA 小于 strB. 零 strA 等于 strB. 大于零 ...
- 深入解析字符串的比较方法:“==”操作符;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。
1:要判断2个字符串变量是否相等,最高效的方法是看它们是否指向相同的内存地址.前面使用RefernceEquals方法来比较.如果2个变量指向的是不同的内存地址,那么就需要逐字符的比较2个字符串的变量 ...
- C# 字符串比较大小 string.Compare()方法
string.Compare方法,用来比较2个字符串值得大小 string.Compare(str1, str2, true); 返回值: 1 : str1大于str2 0 : str1等于str2 ...
- C#基础知识之字符串比较方法:“==”操作符;RefernceEquals;String.Equals方法;String.Compare方法;String.CompareOrdinal方法。
一.“==”操作符:String.Equals:ReferenceEquals 方法 1.在编程中实际上我们只需要这两种比较,c#中类型也就这两种 (1)值类型的比较:一般我们就是判断两个值类型实例各 ...
- String.Compare 方法 (String, Int32, String, Int32, Int32)
String.Compare 方法 (String, Int32, String, Int32, Int32) 对两个指定的 String 对象的子字符串进行比较,并返回一个指示二者在排序顺序中的相对 ...
- C# string.Compare()
tring.Compare方法,用来比较2个字符串值得大小 string.Compare(str1, str2, true); 返回值: 1 : str1大于str2 0 : str1等于str2 - ...
- 【Leetcode_easy】844. Backspace String Compare
problem 844. Backspace String Compare solution1: class Solution { public: bool backspaceCompare(stri ...
- 844. Backspace String Compare
class Solution { public: bool backspaceCompare(string S, string T) { int szs=S.size(); int szt=T.siz ...
- STL || HDU 1894 String Compare
如果一个词包含再另一个词的前面(前缀),是一对前缀,求一共有多少对 *解法:STL万岁 #include<string>:https://www.cnblogs.com/SZxiaochu ...
随机推荐
- 【VS开发】CTabView多页卡界面
转载地址:http://blog.csdn.net/akof1314/article/details/5618454 目录(?)[-] Public Methods Protected Methods ...
- struts框架之环境搭建(一)
一.首先,我们需要做一些准备工作: 1.1. 下载struts:https://struts.apache.org/download.cgi#struts2520 1.2. 下载tomcat:ht ...
- PYTHON 100days学习笔记001:初识python
现在学习这个确实时间很紧,但是迟早得学,以后PYTHON自动化运维,PYTHON自动测试都需要用的到,甚至可以往数据分析方向发展,刚好最近有数据观组织的python100天计划,就参加了,做好笔记,一 ...
- 实例一 airflow_failover
源码: https://github.com/teamclairvoyant/airflow-scheduler-failover-controller #怎么判断scheduler是running的 ...
- Second largest node in the BST
Find the second largest node in the BST 分析: 如果root有右节点,很明显第二大的node有可能在右子树里.唯一不满足的条件就是右子树只有一个node. 这个 ...
- linux用户和组 只 组的管理
1. groupadd 新建组, 组名最长不能超过32个字节 groupadd -create a new group 语法: groupadd [option] 组名 -g, --gid GID ...
- hdu 4471 区间条件统计 区间 不超过 x 的元素的个数
题目传送门//res tp hdu 目的 对长度为n的区间,m次询问,每次提供一个区间两端点与一个值x,求区间内不超过x的元素个数 n 1e5 m 1e5 ai [1,1e9] (i∈[1,n]) 多 ...
- HDU1285(拓扑排序裸题
..被多组测试坑了一波 #include<iostream> #include<vector> #include<queue> using namespace st ...
- uname、hostname命令
一.uname:显示系统信息. 语法: uname [OPTION] ... 描述 打印某些系统信息. 没有选项,与-s相同. -a,--all ...
- 经验:什么影响了数据库查询速度、什么影响了MySQL性能 (转)
一.什么影响了数据库查询速度 1.1 影响数据库查询速度的四个因素 1.2 风险分析 QPS:Queries Per Second意思是“每秒查询率”,是一台服务器每秒能够相应的查询次数,是对一个特定 ...