Testing C++11 lamdas
May 18, 2013 at 8:35am UTC
Hi all, i recently created a programme that checks if a string is a palindrome, using a lambda.
Unfortunately, it does not work. When I type "ama", it does not say it's a palindrome.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
/********************************************************************
aim:
-
********************************************************************/
//headers
#include <iostream>
#include <algorithm>
//namespaces
using namespace std;
//other definitions and declarations
//main function
int main()
{
string str;
auto isPalindrome=[&]{string tmp(str);reverse(tmp.begin(),tmp.end());
if (str==tmp) cout<<"\n\n" <<str<<" is a palindrome!" ;};
cout<<"Please enter text: " ;
getline(cin,str);
isPalindrome;
return 0;
}
Aceix.
May 18, 2013 at 8:40am UTC
Thanks for reading. Anyway the problem has been solved.
How? isPalindrome(); i just added the brackets like a function call.
Aceix.
Topic archived. No new replies allowed.