Skip to content

Commit 98462f4

Browse files
committed
tmp1
1 parent 0eada5a commit 98462f4

File tree

5 files changed

+50
-0
lines changed

5 files changed

+50
-0
lines changed

15/06/b.cpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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+
}

15/06/c.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

15/06/d.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
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+
}

15/06/e.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
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+
}

15/slides.pptx

2.35 MB
Binary file not shown.

0 commit comments

Comments
 (0)