سؤال

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