{
string input; // our input string
vector<string> s_words; // to contain our words
string new_word; // for building the words
cout << "Enter a 4 word sentence: ";
getline (cin, input); // get our input
for (int i = 0; i < input.size(); i++) // for each char in input
{
if (input.at(i) == " ") // if char equal to space
{
if (new_word.size() > 0) // if we have something in new_word
{
s_words.push_back(new_word); // add it to our array
new_word = ""; // clear new_word
}
continue; // go to next iteration of loop
}
new_word.push_back(input.at(i)); // add char to new_word
}
if (s_words.size() != 4) // if we have other than 4 words
{
cout << "Incorrect number of words." << endl; // cout error
return 0; // exit program
}
cout << "Reversed sentence: " << endl;
for (int i = 3; i >= 0; i--) // for each word in reverse
cout << s_words.at(i) << " "; // cout the word