c++codeblocksgetchconio

Defining getch() function in c/c++


Why when I use getch() function in c++, I should include "conio.h" header file ... while in c it runs without include this file?

I'm using codeBlocks as my IDE.

I expect that I must include "conio.h" in c program also, and I tried to include "stdio.h" and "stdlib.h" in c++ program but there is no result.


Solution

  • Why when I use getch() function in c++, I should include "conio.h" header file ...

    C++ requires that identifiers be declared before they are used.

    … while in c it runs without include this file?

    You are using an implementation of an old version of C in which a function call with an undeclared identifier defaulted to treating the identifier as one for a function with undeclared parameters with return type int.

    I'm using codeBlocks as my IDE.

    The IDE is irrelevant, except that there are some associations between some IDEs and some sets of development tools. The critical information is the name and version number of the compiler and the switches you are giving to it. Saying what IDE you are using is like saying what picture frame you are using in a question about a picture. The frame does not identify the picture, and the IDE does not identify the compiler you are using inside the IDE.