Domanda

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++

È stato utile?

Soluzione

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

Altri suggerimenti

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");
}
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top