-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring1in_cpp.cpp
More file actions
26 lines (19 loc) · 802 Bytes
/
Copy pathstring1in_cpp.cpp
File metadata and controls
26 lines (19 loc) · 802 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
#include <iostream>
#include <string>
using namespace std;
int main() {
string str = "There are two needles in this haystack with needles.";
string str2 = "needle";
size_t found;
if ((found = str.find(str2)) != string::npos)
cout << "first 'needle' found at: " << found << '\n';
if ((found = str.find("needles are small", found + 1, 6)) != string::npos)
cout << "second 'needle' found at: " << found << '\n';
if ((found = str.find("haystack")) != string::npos)
cout << "'haystack' also found at: " << found << '\n';
if ((found = str.find('.')) != string::npos)
cout << "Period found at: " << found << '\n';
str.replace(str.find(str2), str2.length(), "preposition");
cout << str << '\n';
return 0;
}