I want to display a sentence in reverse order. For eg "I have money" to "money have I". I have used stack like this but I don't understand why I can't push elements into my stack (stack size always = 0 when I check at the end)
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s;
    cin >> s;
    string temp;
    stack<string> stk;
    for (int i = 0; i < s.size(); i++) {
        if (s[i] != ' ') {
           temp.push_back(s[i]);
           cout << temp << endl;
        } else {
            stk.push(temp);
            temp = "";
        }
    }
    for (int i = 0; i < stk.size(); i++) {
        cout << stk.top() << endl;
        stk.pop();
    }
    cout << stk.size();
}
 
     
     
    