String Fehlermeldung



  • Folgendes Programm, Welches für einen Wochentag einen Wert einlesen soll:

    #include<iostream>
    #include<vector>
    #include<string>
    using namespace std;
    
    int main(){
        vector<int> Montag;
        vector<int> Dienstag;
        vector<int> Mittwoch;
        vector<int> Donnerstag;
        vector<int> Freitag;
        vector<int> Samstag;
        vector<int> Sonntag;
        int werthalter=0;
        char entscheidung;
        string wochentag;
    
        cout<<"Geben Sie bitte ein entsprechendes Wochentag Wert-Paar ein:";
        cin>>wochentag;>>werthalter;
    
        if (wochentag == 'Montag'){
            Montag.push_back(werthalter);
    
        }   
    
        return 0;
    }
    

    bekomme die Fehlermeldung

    g++    -c -g -std=c++11 -MMD -MP -MF "build/Debug/GNU-Linux-x86/main.o.d" -o build/Debug/GNU-Linux-x86/main.o main.cpp
    main.cpp:23:22: warning: character constant too long for its type [enabled by default]
         if (wochentag == 'Montag'){
                          ^
    main.cpp: In function ‘int main()’:
    main.cpp:23:19: error: no match for ‘operator==’ (operand types are ‘std::string {aka std::basic_string<char>}’ and ‘int’)
         if (wochentag == 'Montag'){
                       ^
    

    Was hat der Compiler für ein Problem ?



  • Du musst zumindeste doppelte Anführungszeichen verwenden, einzelne sind für chars. Ob da noch mehr Fehler drin sind, weiß ich nicht, hab mir den Rest nicht angschaut.



  • Danke..! mit doppelten geht's


Anmelden zum Antworten