Frage: jedes Mal, wenn ich das Programm ausführen und ich eingeben, wer Sie sind, sagt es Fehlerwert von a stimmt nicht überein, was vor sich geht? (Ja, ich bin ein noob zu C++) Code:Ich laufe weiter in Probleme mit, wenn elif und sonst in C++
#include <iostream>
using namespace std;
int main() {
// local variable declaration:
string a;
cin >> a;
// check the boolean condition
if(a == "hello") {
// if condition is true then print the following
cout << "hi" << endl;
} else if(a == "who are you") {
// if else if condition is true
cout << "a better question is who are you?" << endl;
} else if(a == "what am i doing") {
// if else if condition is true
cout << "reading this output " << endl;
}else {
// if none of the conditions is true
cout << "Error Value of a is not matching" << endl;
}
return 0;
}
'cin >> a' liest nur ein Wort. Wie kann es gleich "Wer bist du" sein? – Barmar
Lesen Sie die Zeichenfolge mit std :: getline() –
Wenn Sie versucht haben, "a" zu drucken, hätten Sie das Problem sofort gesehen. – Barmar