mirror of
https://hub.njuu.cf/TheAlgorithms/C-Plus-Plus.git
synced 2023-10-11 13:05:55 +08:00
2a7243e58a
* added #include <cstdlib> - it was causing compile time error * made code and output more readable * removed unused variables * repositions some conditions in logical manner
40 lines
1.0 KiB
C++
40 lines
1.0 KiB
C++
#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");
|
|
}
|
|
|
|
}
|
|
}
|