Answer:
#include <iostream>
#include <string>
using namespace std;
int main() {
string sentence1, sentence2, word1, word2;
cout << "Enter the first sentence: ";
getline(cin, sentence1);
cout << "Enter the second sentence: ";
getline(cin, sentence2);
stringstream s1(sentence1), s2(sentence2);
while (s1 >> word1 && s2 >> word2) {
if (word1 != word2) {
cout << word1 << " " << word2 << endl;
}
}
return 0;
}
Step-by-step explanation:
two strings sentence1 and sentence2 are read from the user. The stringstream class is used to extract words from the sentences, one word at a time, and store them in the word1 and word2 variables. The >> operator is used to extract words from the stringstreams, and the while loop continues until either stringstream is empty. If the words word1 and word2 are not equal, they are displayed as a word pair on a separate line.