質問

I have my program here.

#include <iostream>
#include <string>
using namespace std;
int main()
{
string input;
cout << "say yes or no" << endl;
cin >> input;
if(input == Yes)
{
    cout << "test" << endl;
}
else if(input == No)
{
    cout << "test123" << endl;
}
system("pause");
}

It says that Yes and No are undefined? Please help I am new to c++

役に立ちましたか?

解決

You should use doubleQuotes for string "Yes" "No"

他のヒント

First, Yes and No without double quote are read as variable by the compilator, and you didn't declare any Yes or No variable.

Second, I don't think you can compare String like that in C++ : you have to use compare ( http://www.cplusplus.com/reference/string/string/compare/ ) so the prog will be :

#include <iostream>
#include <string>
using namespace std;
int main()
{
  string input;
  cout << "say yes or no" << endl;
  cin >> input;
  if(input.compare("Yes"))
  {
    cout << "test" << endl;
  }
  else if(input.compare("No"))
  {
    cout << "test123" << endl;
  }
  system("pause");
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top