trying to reverse a string

May 25, 2016 at 3:29pm
hi guys I'm trying to reverse a string but I get an error using the reverse function
#include <iostream>
#include <string>
#include<algorithm>

using namespace std;

int main()
{

string one("hello");
reverse(one.at(0),one.at(4));
}

[/code]
Last edited on May 25, 2016 at 3:32pm
May 25, 2016 at 3:45pm
When you have an error, it would often be really, really helpful if you told us instead of making us guess. Seriously, coming to us and saying "I've got a problem" and then not telling us what the problem is? Surely you can understand that it would be much more helpful if you told us what the problem was. Your compiler said something. That's how you know what the problem is. If you want us to also know, you need to tell us as well.

As it is, this one I can see.

reverse(one.at(0),one.at(4));

one.at(0) is a char.
one.at(4) is a char.
This function, reverse, does not accept two char as parameters. It accepts iterators.

1
2
3
4
5
6
7
8
9
#include <iostream>
#include <string>
#include<algorithm>
using namespace std;
int main()
{
string one("hello");
reverse(one.at(0),one.at(4));
}
Last edited on May 25, 2016 at 3:47pm
May 25, 2016 at 3:58pm
Thanks Moschops,I normally would give the compiler error message but the message is lines and lines long so it would take a huge amount of time to write out

so basically only intergers are accepted by this function?
Topic archived. No new replies allowed.