-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathstringFind.cpp
More file actions
28 lines (20 loc) · 934 Bytes
/
stringFind.cpp
File metadata and controls
28 lines (20 loc) · 934 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#include <iostream>
#include <string>
using namespace std;
int main() {
string text = "I can resist anything but temptation.";
int num;
num = text.find("resist", 0); //finds the first occurrence of "resist" at position 0
cout << "Position of first occurrence of \"resist\": " << num << endl;
num = text.find("nonsuch", 0); //finds the first occurrence of "nonsuch" at position 0
cout << "Position of first occurrence of \"nonsuch\": " << num << endl;
num = text.find_first_of("If");
cout << "Position of first occurrence of \"If\": " << num << endl;
num = text.find_first_not_of("If");
cout << "Position of first occurrence of non-\"If\": " << num << endl;
num = text.find_last_of("t");
cout << "Position of last occurrence of \"t\": " << num << endl;
num = text.find_last_not_of("t");
cout << "Position of last occurrence of non-\"t\": " << num << endl;
return 0;
}