forked from TheAlgorithms/C-Plus-Plus
-
Notifications
You must be signed in to change notification settings - Fork 2
/
searching.cpp
39 lines (35 loc) · 1.02 KB
/
searching.cpp
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
#include <iostream>
#include <string>
#include <cstdlib>
using namespace std;
char paragraph;
int main()
{
string paragraph;
cout << "Please enter your paragraph: \n";
getline (cin,paragraph);
cout << "\nHello, your paragraph is:\n " << paragraph << "!\n";
cout << "\nThe size of your paragraph = " << paragraph.size() << " characters. \n\n";
if (paragraph.empty())
{
cout << "\nThe paragraph is empty" << endl;
}
else
{
while (true) {
string word;
cout << "Please enter the word you are searching for: ";
getline (cin,word);
cout << "Hello, your word is " << word << "!\n";
if (paragraph.find(word) == string::npos)
{
cout << word << " does not exist in the sentence" << endl;
}
else
{
cout << "The word " << word << " is now found at location " << paragraph.find(word) << endl << endl;
}
system("pause");
}
}
}