im trying to write a program inputs some words and uses a stack object to print the line in reverse. when i run my program it gives me the word the right way not reversed. for ex: hello there it gives me hello there
what am i doing wrong?
Code:#include <iostream> #include <stack> #include <string> using namespace std; int main() { stack<string> allwords; // stack of all words string word; // input for words. cout << "enter some words: "; getline(cin, word); allwords.push(word); while (!allwords.empty()) { cout << allwords.top() << endl; allwords.pop(); } return 0; }




Reply With Quote