Undeclared identifier

#include <iostream>
using namespace std;
int main()

{
char password[16];
cout << "Password, please? ";
cin >> password;
if (password == anevilvegetable)
cout << "Here's your serial: SERIAL" << endl;
else
cout << "Wrong password. Please try again. " << endl;
system("pause");
return 0;
}
-----------------------------------------------------------------------------
Why can't I have "anevilvegetable" as "password"? It gives me:

error C2065: 'anevilvegetable' : undeclared identifier


try making password a string instead of an array?
like for example this runs perfectly


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
#include <iostream>
using namespace std;
int main()

{
string password;
cout << "Password, please? ";
cin >> password;
if (password == "anevilvegetable")
cout << "Here's your serial: SERIAL" << endl;
else 
cout << "Wrong password. Please try again. " << endl;
system("pause");
return 0;
}
You lack the " s for anevilvegetable: "anevilvegetable"
@oppositescopez

We've not talked about "string". That's why. I started with C++ a week ago, so I'm new to this. Java is a little bit different.
But I've changed the code to yours, but it gives me the following error:
1. "cin >> password;" - "ERROR: No operator ">>" matches these operands"
2. If (password == "anevilvegetable") - "ERROR: No operator "==" matches these operands"
@samrux

No, if I put those there, it gives me more errors.
closed account (28poGNh0)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# include <iostream>
# include <string>
using namespace std;

int main()
{
string password;

cout << "Password, please? " << endl;
getline(cin,password);

if (password.compare("anevilvegetable")==0)
cout << "Here's your serial: SERIAL" << endl;
else
cout << "Wrong password. Please try again. " << endl;
// Dont use system("pause");
cin.get();
return 0;
}


I am so so tired
Last edited on
If you're going to use the string class, as suggested, you'll need to #include <string> .

If you're using character arrays (or C strings), as in your original code, you can compare them using the strcmp_s function. You'll need to #include <cstring> for that function.

closed account (28poGNh0)
iHutch105 ,You have an aigle eyes
I'll edit it dont worry
Topic archived. No new replies allowed.