-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstringExamplePart2.cpp
More file actions
60 lines (47 loc) · 1.21 KB
/
stringExamplePart2.cpp
File metadata and controls
60 lines (47 loc) · 1.21 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//=======================================================
//stringExamplePart2.cpp
//More games with strings
//=======================================================
#include<string>
#include<iostream>
using namespace std;
//Declare procedures
void lookFor(const string & s, const string & pattern);
//=========================>> main <<======================
int main()
{
//declare some strings
string name("Eowyn");
string fathername("Edmund");
string relation;
relation.append(name);
relation.append(" daughter of ");
relation.append(fathername);
cout<<relation<<endl;
cout<<"There are "<<name.size()<<" characters in "
<<name<<endl;
string pattern("i");
lookFor(name,pattern);
pattern="e";
lookFor(name,pattern);
pattern="E";
lookFor(name,pattern);
pattern="bitter";
lookFor(relation,pattern);
pattern="aug";
lookFor(relation,pattern);
return 0;
}
//====================>>lookFor<<======================
//Looks for a match to the pattern in the string s
void lookFor(const string & s, const string & pattern)
{
if(s.npos==s.find(pattern))
{
cout<<"There is no \""<<pattern<<"\" in "<<s<<endl;
}
else
{
cout<<"Found an \""<<pattern<<"\" in "<<s<<endl;
}
}