#include <iostream>
#include <string>
using namespace std;

int main()
{
	string a;
	cout<< "enter string" <<endl;
	cin>> a;

	string b;
//========================================================
	for (int j=a.size(); j>0; j--)
	{
		for (int i=0; i<a.size(); i++)
		{
			b[j]=a[i];
		}
	}
        cout<< b <<endl;
	return 0;
}

i want the first character on string a to be the last char on string b up until the last on a is the first on b. what is the problem in that cycle?
ps: it runs and causes an illegal error table.

> what is the problem
the problem is that string b; creates an empty string. b[j]=a[i]; is incorrect; there are no characters in b.

> i want the first character on string a to be the last char on string b
> up until the last on a is the first on b
this would suffice.

#include <iostream>
#include <string>
using namespace std;

int main()
{
  string a;
  cout<< "enter string" <<endl;
  cin>> a;

  string b( a.rbegin(), a.rend() ) ;
  cout<< b <<endl;
}
This question has already been answered. Start a new discussion instead.