Skip to content

Commit bd29d61

Browse files
committed
add string.compare()
1 parent e2ea62c commit bd29d61

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

cpp_lib_instruction/string.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,18 @@ string s;
99
1010
// 初始化
1111
12-
// 子字符串
13-
string sss = s.substr(pos, n); // 返回字符串s中,自pos起,长度为n的子字符串
12+
// 子字符串/substr
13+
string s2 = s.substr(pos, n); // 返回字符串s中,自pos起,长度为n的子字符串
14+
string s3 = s.substr(pos); // 自pos起,至s末尾
15+
// 若pos超出s的长度,则返回out_of_range异常
16+
17+
// 比较/compare 相等返回0,s1<s2返回负数,s1>s2返回正数
18+
// 1. s与s2
19+
s.compare(s2)
20+
s.compare(pos1,n1,s2)
21+
s.compare(pos1,n1,s2,pos2,n2)
22+
// 2. s与字符数组cp
23+
s.compare(cp) // 比较s与cp指向的以空字符结尾的字符数组
24+
s.compare(pos1,n1,cp)
25+
s.compare(pos1,n1,cp,n2) // s[pos1:pos1+n1] 与 cp[0:n2]
1426
```

0 commit comments

Comments
 (0)