Happy Codings - Programming Code Examples
Html Css Web Design Sample Codes CPlusPlus Programming Sample Codes JavaScript Programming Sample Codes C Programming Sample Codes CSharp Programming Sample Codes Java Programming Sample Codes Php Programming Sample Codes Visual Basic Programming Sample Codes

C++ Programming Code Examples

Learn C++ Language

kbhit() Function in C++ Programming Language

kbhit() Function in C++
The kbhit is basically the Keyboard Hit. This function is present at conio.h header file. So for using this, we have to include this header file into our code. The functionality of kbhit() is that, when a key is pressed it returns nonzero value, otherwise returns zero. kbhit() is used to determine if a key has been pressed or not. If a key has been pressed then it returns a non zero value otherwise returns zero.
Syntax for kbhit() Function in C++
#include <conio.h> int kbhit();
Function returns true (non-zero) if there is a character in the input buffer, otherwise false. Note : kbhit() is not a standard library function and should be avoided.
/* kbhit() function is not defined as part of the ANSI C/C++ standard. It is generally used by Borland's family of compilers. It returns a non-zero integer if a key is in the keyboard buffer. It will not wait for a key to be pressed. */ // C++ program code example to fetch key pressed using kbhit() #include <conio.h> #include <iostream> int main() { char ch; while (1) { if (kbhit) { // Stores the pressed key in ch ch = getch(); // Terminates the loop // when escape is pressed if (int(ch) == 27) break; cout << "Key pressed= " << ch; } } return 0; }

To print "Pascal Triangle" in C++, you have to enter the Number of Line. So to Print "Pascal Triangle", you have to use three For Loops as shown here in the C++ Programming samples

To convert binary to octal in C++, you have to ask to the user to enter any number in binary to "convert it into octal" to display equivalent value in octal on the screen as shown in code