error with std::reverse

Here is my function, taking an integer as an argument, then reversing it and comparing the original to see if the number is a palindrome.

1
2
3
4
5
6
7
8
  bool isPalindrome(int n) {
	string num = to_string(n);
	string rNum = reverse(num.begin(), num.end());
	if(num == rNum)
		return true;
	else
		return false;
}


I keep getting the following compiler error:


Untitled.cpp:25:9: error: no viable conversion from 'void' to 'string' (aka 'basic_string<char, char_traits<char>, allocator<char> >')
        string rNum = reverse(num.begin(), num.end());


Help would be appreciated. Thanks.
Last edited on
reverse does not returns a value and instead operates in place, modifying num. I suggest to use reverse iterators and string iterator constructor:
1
2
string num = to_string(n);
string rNum(num.rbegin(), num.rend());
It worked. Thanks!
Topic archived. No new replies allowed.