Problem z transform

2

Mam poniższy kod, który niestety nie kompiluje się.

 
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string slowo;
    cout << "Podaj slowo: ";
    getline(cin,slowo);
    cout << endl;

    transform(slowo.begin(),slowo.end(),slowo.begin(),tolower);

    cout << "Slowo '" << slowo << "' ";

    string slowo_x (slowo); //przypisanie
    reverse(slowo.begin(),slowo.end());

    if(slowo==slowo_x)
    {
        cout << "jest palindromem.";
    }
    else
    {
        cout << "nie jest palindromem";
    }
    cout << endl;

    return 0;
}

Błąd powoduje ta linijka. Oczywiście po jej wykomentowaniu przez // wszystko jest ok.

transform(slowo.begin(),slowo.end(),slowo.begin(),tolower);

Nie wiem, o co chodzi. Środowisko Code::Blocks.

Błąd: Klasa string - palindrom\main.cpp||In function 'int main()':|
Klasa string - palindrom\main.cpp|14|error: no matching function for call to 'transform(__gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, __gnu_cxx::__normal_iterator<char*, std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, <unresolved overloaded="overloaded" function="function" type="type">)'|
== Build finished: 1 errors, 0 warnings ===

0

Może dołącz nagłówek z deklaracją funkcji tolower http://www.cplusplus.com/reference/clibrary/cctype/tolower/ lub tak http://www.cplusplus.com/reference/std/locale/ctype/tolower/

Czy chodzi o dodanie dyrektywy preprocesora ? Dodawałem, ale problem chyba nie leży po stronie kodu, bo ctype.h jest i tak dodawana "automatycznie".

2

Sam do końca nie wiem w czym jest problem, ale ewidentnie kompilator gdzieś ma trudności z określeniem typu funkcji.
Powiedzenie explicite jaki on jest pomaga:

transform(slowo.begin(),slowo.end(),slowo.begin(),static_cast<int(*)(int)>(tolower));

I program śmiga.

0
transform(..., &::tolower);

1 użytkowników online, w tym zalogowanych: 0, gości: 1