Algorithms_in_C++  1.0.0
Set of algorithms implemented in C++.
text_search.cpp File Reference

Search for words in a long textual paragraph. More...

#include <cstdlib>
#include <iostream>
#include <cstring>
Include dependency graph for text_search.cpp:

Functions

int main ()
 

Detailed Description

Search for words in a long textual paragraph.

Function Documentation

◆ main()

int main ( void  )

Main function

15  {
16  std::string paragraph;
17  std::cout << "Please enter your paragraph: \n";
18  std::getline(std::cin, paragraph);
19  std::cout << "\nHello, your paragraph is:\n " << paragraph << "!\n";
20  std::cout << "\nThe size of your paragraph = " << paragraph.size()
21  << " characters. \n\n";
22 
23  if (paragraph.empty()) {
24  std::cout << "\nThe paragraph is empty" << std::endl;
25  } else {
26  while (true) {
27  std::string word;
28  std::cout << "Please enter the word you are searching for: ";
29  std::getline(std::cin, word);
30  std::cout << "Hello, your word is " << word << "!\n";
31  if (paragraph.find(word) == std::string::npos) {
32  std::cout << word << " does not exist in the sentence"
33  << std::endl;
34  } else {
35  std::cout << "The word " << word << " is now found at location "
36  << paragraph.find(word) << std::endl
37  << std::endl;
38  }
39  std::cin.get();
40  }
41  }
42 }
Here is the call graph for this function:
std::string
STL class.
std::cout
std::endl
T endl(T... args)
std::getline
T getline(T... args)
std::cin