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
	}
	

}

Recommended Answers

All 4 Replies

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

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

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

Still good for that beer?

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.