Reverse string

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
int _tmain(int argc, _TCHAR* argv[])
{
	string input;
	
	cout<<"write something"<<endl;
	getline(cin,input);
	string test;
	int len = input.length();
	while(len!=0)
		{	
			len--;
			test=input[len];
				
		}
	cout<<test;
	cin.get();
	return 0;
}


with this code program shows first character of my input but i want the insert the whole reversed string

thanks

sorry for my english
test=input[len];
think about what this line does
I understand a problem little bit
every turn writes one character when loop over the last character is input's first character and test's value is first character of input

but i got no idea how to do please help

sorry for my english
Last edited on
Set test to its current value in addition to the new character:
test = test + input[len];

Another way to write that is:
test += input[len];

Or you can do:
test.append(1, input[len]);
Last edited on
Topic archived. No new replies allowed.