transform Problem mit Dev-C++



  • /* http://www.josuttis.com/libbook/string/iter1.cpp.html */
    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <cctype>
    using namespace std;
    
    int main()
    {
        // create a string
        string s("The zip code of Hondelage in Germany is 38108");
        cout << "original: " << s << endl;
    
        // lowercase all characters
        transform (s.begin(), s.end(),    // source
                   s.begin(),             // destination
                   tolower);              // operation ??
        cout << "lowered:  " << s << endl;
    
        // uppercase all characters
        transform (s.begin(), s.end(),    // source
                   s.begin(),             // destination
                   toupper);              // operation ??
        cout << "uppered:  " << s << endl;
    }
    

    Dev-C++ scheitert hier an tolower und toupper. Wie geht das richtig?



  • wie lautet die fehlermeldung?



  • 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> > >, <unknown type>)'

    C:/C++_online_Schule/Programme/10 STL, Templates/C++_String/string_transform_funktioniert_noch_nicht.cpp:26: 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> > >, <unknown type>)'

    Ausführung beendet



  • Hm, der Code scheint korrekt zu sein.
    Und Copy+Paste+F5 liefert mit VC7.1 auch das gewünschte Ergebnis.

    MfG Jester



  • welche gcc version fährst du?

    ich denke, hier könnte es interessant werden
    frage:
    http://gcc.gnu.org/ml/gcc-bugs/2003-06/msg00742.html
    erste antwort:
    http://gcc.gnu.org/ml/gcc-bugs/2003-06/msg00750.html

    The program is not required to work and GCC is NOT in error.

    [...]

    | string lcase (const string & s)
    | {
    |     string result = s;
    |     transform (result.begin(), result.end(), result.begin(), tolower);
    

    This is a known issue. See the FAQ and a recent talk of mine and
    Benjamin's at the recent ACCU conference.

    This PR can be closed as not a defect.

    http://linux-rep.fnal.gov/software/gcc/onlinedocs/libstdc++/22_locale/howto.html#7

    http://www.accuconference.co.uk/speakers2003.asp#Gabriel



  • Hallo,
    eine andere Lösung (denke ich) als die vorgestellte wäre ein expliziter Cast:

    #include <string>
    #include <iostream>
    #include <algorithm>
    #include <cctype>
    using namespace std;
    
    int main()
    {
        // create a string
        string s("The zip code of Hondelage in Germany is 38108");
        cout << "original: " << s << endl;
    
        // lowercase all characters
        transform (s.begin(), s.end(),    // source
                   s.begin(),             // destination
                  static_cast<int(*)(int)>( tolower));              // operation ??
        cout << "lowered:  " << s << endl;
    
        // uppercase all characters
        transform (s.begin(), s.end(),    // source
                   s.begin(),             // destination
                   static_cast<int(*)(int)>(toupper));              // operation ??
        cout << "uppered:  " << s << endl;
    }
    


  • ist keine andere... die da oben im gcc forum kommen auf die gleiche 😉



  • hallo

    int main()
    

    wie wäre es mit einem rückgabewert wie

    return 0;
    

    ?

    tschüss



  • rulzmaker schrieb:

    wie wäre es mit einem rückgabewert wie

    return 0;
    

    Ist nicht nötig, main gibt laut Standard per Default 0 zurück.



  • elise schrieb:

    ist keine andere... die da oben im gcc forum kommen auf die gleiche 😉

    Ups. Sowas passiert, wenn man zu früh morgens, unter Zeitdruck kurz vor einer Abschlusspräsentation noch schnell seine Hilfe anbieten will 🙂



  • Du hast beim allerersten Code bei tolower und touper die 1. Klammer vergessen

    tolower);              // operation ??
    


  • Da fehlt keine Klammer.


Anmelden zum Antworten