File tree Expand file tree Collapse file tree 5 files changed +50
-0
lines changed Expand file tree Collapse file tree 5 files changed +50
-0
lines changed Original file line number Diff line number Diff line change
1
+ #include < string>
2
+ #include < iostream>
3
+
4
+ using namespace std ;
5
+
6
+ int main () {
7
+ string s = " helloworld" s;
8
+ cout << " 从第2个字符开始长为5的子字符串: " << s.substr (2 , 4 ) << endl;
9
+ cout << " 从第2个字符开始长为99的子字符串: " << s.substr (2 , 99 ) << endl;
10
+ cout << " 从第2个字符开始直到末尾的子字符串: " << s.substr (2 ) << endl;
11
+ cout << " 从头开始长为5的子字符串: " << s.substr (0 , 4 ) << endl;
12
+ cout << " 从第100个字符开始长为5的子字符串: " << s.substr (100 , 5 ) << endl;
13
+ }
Original file line number Diff line number Diff line change
1
+ #include < string>
2
+ #include < iostream>
3
+
4
+ using namespace std ;
5
+
6
+ int main () {
7
+ string s = " helloworld" s;
8
+ cout << " 寻找h的结果:" << s.find (' h' ) << endl;
9
+ cout << " 寻找e的结果:" << s.find (' e' ) << endl;
10
+ cout << " 寻找l的结果:" << s.find (' l' ) << endl;
11
+ cout << " 寻找o的结果:" << s.find (' o' ) << endl;
12
+ cout << " 寻找H的结果:" << s.find (' H' ) << endl;
13
+ cout << " (size_t) -1:" << (size_t )-1 << endl;
14
+ }
Original file line number Diff line number Diff line change
1
+ #include < string>
2
+ #include < iostream>
3
+
4
+ using namespace std ;
5
+
6
+ int main () {
7
+ string s = " helloworld" s;
8
+ cout << boolalpha;
9
+ cout << " h: " << (s.find (' h' ) != string::npos) << endl;
10
+ cout << " z: " << (s.find (' z' ) != string::npos) << endl;
11
+ }
Original file line number Diff line number Diff line change
1
+ #include < string>
2
+ #include < iostream>
3
+
4
+ using namespace std ;
5
+
6
+ int main () {
7
+ string s = " helloworld" s;
8
+ cout << boolalpha;
9
+ cout << " lo: " << s.find (" lo" ) << endl;
10
+ cout << " wo: " << s.find (" wo" ) << endl;
11
+ cout << " ma: " << s.find (" ma" ) << endl;
12
+ }
You can’t perform that action at this time.
0 commit comments