0

I commented by the last line. I am trying to print out the string in reverse.

#include <iostream>
using namespace std;
void add(string n);

int main()
{
	string B ="ABCDEF";
	add(B);
	
}

void add(string n)
{	
	if(n.length() <= 1)
	{
		cout<<n[0]<<endl;
		return;
	}
	else
	{
		cout<<n[n.length()-1];
		add(n[n.length()-1]);  //this lines does not work cannot covert char to string
	}
	

}
2
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Euphan
0

try this line instead of the one that doesn't work:
add(n.substr(0,n.length()-1));

0

Thank you, if are ever in Seattle and 21 or over I'll buy you a beer

0

hehe. I actually live north of seattle, and I'm over 21, but I don't drink :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.