質問: (はい、私はC++にnoobのだ) コード:もし私がプログラムを実行するたびにエラーの値が何が起こっているかとは違うと言う人を入力するたびに、私はelifとか他の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'は1語だけを読みます。あなたは誰ですか? – Barmar
std :: getline()を使用して文字列を読み込みます –
'a'を印刷しようとするとすぐに問題が発生していました。 – Barmar