C ++での_getch()とgetchar()の違い



Difference Between _getch



2つの違い:
_getch()は、プログラミングで使用される関数です。この関数は非エコー関数です。ユーザーが文字を押すと、Enterキーを押さなくても関数が自動的に読み取られます。一部のC言語コマンドラインプログラムは、この関数を使用してゲームを一時停止しますが、この関数は標準の関数ではありません。
getch()関数に必要なヘッダーファイル:conio.h、関数プロトタイプ:int getch(void)
例えば:
#include
charchまたはintch
getch()またはch = getch()
getch()を使用すると、次のステートメントの実行を続行する前に、任意のキーが押されるのを待ちます。
ch = getch()を使用すると、任意のキーが押されるのを待ち、キー文字に対応するASCIIコードをchに割り当ててから、次のステートメントを実行します。

getchar()は一種の読み取り関数です。 getc(stdin)と同等の標準入力から次の文字を読み取ります。戻り値の型はintです。
getchar()関数はstdio.hヘッダーファイルで宣言されており、使用する場合はstdio.hヘッダーファイルをインクルードする必要があります。といった:
#include
int getchar(void)



コードは次のように表示されます。
#include
#include
#include
名前空間stdを使用する

int main()
{{
char order = _getch()
while(_kbhit)
{{



if (order=='W'||order=='w') { cout << '_getch() function: do not display echo (input automatic output)...' << endl break } } char order1 = getchar() while (_kbhit) { if (order1 == 'W' || order1 == 'w') { cout << 'getchar() function: will display echo (press enter to output)...' << endl break } } _getch() //used to pause //system('pause') //Similar to the upstream code function, generally used ('pause') return 0 }

画像