I read data with space using getline, I reverse it. but it gives back a space added. You can see the code below.
#include <iostream>
#include <string>
using namespace std;
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
string s;
getline(cin, s);
for (int i = s.length(); i >= 0; i--) {
cout << s[i];
}
return 0;
}
When I enter:aaa it gives back: aaa
A space added at first.
How to fix this?