terminate called after throwing an instance of std::out_of_range

#include <iostream>
#include <string>

using namespace std;

int main()
{
string input;

cout << "Enter a word: ";
getline(cin, input);

for (int j=input.length(); j>=0; j--)
{
cout << input.at(j);

}

cout << endl;

return 0;
}

When I run this program it says "terminate called after throwing an instance of std::out_of_range". Thank you in advance.
closed account (E0p9LyTq)
You are going out of bounds, your starting condition should be input.length() - 1.
Topic archived. No new replies allowed.