I am trying to reverse the words in a string using this code:
#include <bits/stdc++.h>
using namespace std;
int main()
{
    //_ _ the sky is blue
    string vec;
    getline(cin, vec);
    stack<string> str;
    string temp = "";
    string ans = "";
    for (int i = 0; i < vec.length(); i++)
    {
        if (vec.at(i) == ' ')
        {
            if (temp.length() > 0)
            {
                str.push(temp);
                temp = "";
            }
            else
            {
                temp = temp + vec.at(i);
            }
        }
    }
    //ans = ans + temp;
    while (!str.empty())
    {
        ans = ans + " " + str.pop();
    }
    if (ans.length() != 0 && ans.at(0) == ' ')
        ans = ans.substr(1);
    cout << ans << endl;
}
I'm receiving this error at line 33 telling "no match for 'operator+'".
I have attached the relevant screenshot:
Please, help.

 
     
     
    