#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;
}

thanks..so the problem was nowhere near where i anticipated :|

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.