[Solved] What's the exact difference between getchar() and getche() functions in C++ ? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 16

[Solved] What's the exact difference between getchar() and getche() functions in C++ ?

Eg: In ch = getchar() The character is inputted through the keyboard and stored in ch And In ch = getche() The character input will be stored in ch. The typed character will be echoed on the screen It seems both function does the same 🤷🏻‍♂️ Please help me find the difference! NB: Some of them who answered confused the functions in the questions with other similar functions ⚠️ Edit: Finally, I came to a conclusion, my school syllabus was terribly wrong & mixing up all the answer I found the that getche() will be echoed and Enter key need not be pressed to delimit data ~ Thanks to Vinay_GB and all others ~

20th Feb 2020, 4:36 PM
A C K
A C K - avatar
8 Answers
+ 12
int getchar() in C++. "...Reads the next character from stdin. Equivalent to std::getc(stdin)." Reference: https://en.cppreference.com/w/cpp/io/c/getchar But, except C, there's no "getche()" function in C++. - you can search in this documentation: https://en.cppreference.com/w/ Or Try this snippet: /* Include all header files in C++ */ #include <bits/stdc++.h> using namespace std; int main(){ getche(); return 0; } Refer to this link below to know the difference of getchar() and getche() functions in C. https://www.geeksforgeeks.org/difference-getchar-getch-getc-getche/amp/
20th Feb 2020, 5:44 PM
Vinay_GB
Vinay_GB - avatar
+ 9
~ swim ~ thats not what Im looking for those links which redirects to websites are about C standard functions and that 1 question was different from what I ask But bro getchar() and getche() does the same 🤷🏻‍♂️
20th Feb 2020, 4:48 PM
A C K
A C K - avatar
+ 9
Sudeep Jaiswal but bro my question was: getchar v/s getche() ✅ and not: getch v/s getche() ❌
20th Feb 2020, 4:51 PM
A C K
A C K - avatar
+ 9
Vinay_GB but bro my school syllabus says getche() as a function in c++ predefined library - stdio 🤷🏻‍♂️ bro, if its C standard functions but what's the difference btw those functions? 🤔
21st Feb 2020, 12:11 AM
A C K
A C K - avatar
+ 8
~ swim ~ yeah, I've visited the sites multiple times & it doesn't provides the mere difference between getchar() and getche() those articles compared the other two functions and not what Im asking, hope you may understand ✅ and also you may to read my question and thos questions carefully, ❌ This is not duplicate question ❌
21st Feb 2020, 12:09 AM
A C K
A C K - avatar
+ 8
#DARK_PROGRAMMER_✔ Thats not my question My question: getchar() vs getche() ✅ your answer: getchar() vs getch() ❌ don't confuse with functions bro
21st Feb 2020, 1:56 AM
A C K
A C K - avatar
+ 7
『 #AVD001 』| Highly-Inactive | Ěxams :/ Perhaps, they must have made mistake. Btw, stdio.h is not C++ programming language's header file but C programming language. In C++ <cstdio> is similar to stdio.h in C.
21st Feb 2020, 1:07 AM
Vinay_GB
Vinay_GB - avatar
+ 4
Getchar() is standard function and is used in almost all compilers Getch() is not standard rather specific with compilers like boreland international In getchar () you must press carriage return/enter key to make it work In getch () you can just press any key and it would take that key as input it also supports various white spaces including enter itself While all type of white spaces especially enter is not supported by getchar () Getch supports all 256 ASCII chars if you have that type of keyboard While getchar () doesn't
20th Feb 2020, 6:11 PM
#DARK_PROGRAMMER_✔
#DARK_PROGRAMMER_✔ - avatar