#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.
You are going out of bounds, your starting condition should be input.length() - 1
.