Cin and functions

Alright the three errors I got and don't understand are these (coming from Microsoft Visual C++ Express Edition)

error C2065: 'cin' : undeclared identifier
error C2446: '==' : no conversion from 'const char *' to 'int'
There is no context in which this conversion is possible
error C2040: '==' : 'int' differs in levels of indirection from 'const char [2]'


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <iostream>

/* 
RPGTeXT
*/

// Start of RPGTeXT
int main()
{
char ready;
char Y;
char N;
	printf ("Welcome to RPGTeXT! \n");
	printf ("Copyright by Suite4Gamers \n");
	printf ("Contact us at imoddedu@suite4gamers.com \n");
	printf ("Lets get the game STARTED!");
	system ("PAUSE");
	//Game Start
	printf ("Welcome to RPGTeXT \n");
	printf ("Are you ready to play? \n");
	printf ("Type Y for Yes \n");
	printf ("Type N for No \n");
	cin>>ready;
	{
	if (ready == "Y")
		system ("PAUSE");
	}

	
}
// End of RPGTeXT 

error C2065: 'cin' : undeclared identifier


cin is part of the std namespace. Either explicitly invoke the std namespace by using std::cin or put using namespace std; at the top of your file after the includes.

error C2446: '==' : no conversion from 'const char *' to 'int'

'ready' is of type char. "Y" is a string. You probably want to compare to the character Y and not the string Y (there's a difference).

'Y' = the character
"Y" = the string
Please note that printf() is a C style of output. While it still has valid uses most people prefer the C++ method of using cout.

If you want to better understand cin and how to avoid a few common bugs read through: http://www.cplusplus.com/forum/articles/6046/
btw you dont need
1
2
char Y;
char N;

because you can say 'Y' instead of Y = 'Y' then call for Y..it's kind of redundant code

um like Disch said...just use 'Y' not "Y". you're checking a character..the value would be 'Y'
Topic archived. No new replies allowed.