Click here to Skip to main content
15,919,341 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C++
c1=(char)_getch();
Posted
Updated 9-Nov-15 16:53pm
v2
Comments
[no name] 9-Nov-15 22:35pm    
Too trival to post a solution - Get a character from console (keyboard) and cast it to a signed char (not clever).
https://msdn.microsoft.com/en-us/library/ms235446.aspx
Please learn to use Google.
Sergey Alexandrovich Kryukov 9-Nov-15 22:35pm    
It means that you have to learn some C++ before asking questions. Which part of this line is not clear to you?
—SA
Patrice T 9-Nov-15 22:48pm    
Please help yourself and do minimum research before asking question.
Your question claim to the word how stupid you are, not even able to perform the most basic research.
PIEBALDconsult 9-Nov-15 22:53pm    
Ease up there, mate.
Patrice T 9-Nov-15 22:57pm    
Ok, but when I see this kind of question, sometimes I can't help.

1 solution

Please see my comment to the question, which is not quite productive.

This is C-style typecast, (char), performed over the value returned by the function _getch(). Depending on the profile of _getch(), it may or make not make sense. The type char is ANSI (non-Unicode) 8-bit character, something which is majorly obsolete. This function, most likely, might be this one, which would require typecast if you need char:
https://msdn.microsoft.com/en-us/library/078sfkak.aspx[^],
see also: http://stackoverflow.com/questions/814975/getch-is-deprecated[^].

This is all old stuff. One C++ way which would not require this ugly type casting is using cin and cout streams: http://www.cplusplus.com/doc/tutorial/basic_io[^].

I think it has its own ugliness and I remember that one of our high-reputation members claimed he hates it; which I would understand, but typecasting for reading from console is worse.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900