控制台和端口 I/OConsole and Port I/O

这些例程在控制台或指定端口上读写。These routines read and write on your console or on the specified port. 控制台 I/O 例程与流 I/O 或低级 I/O 库例程不兼容。The console I/O routines are not compatible with stream I/O or low-level I/O library routines. 在执行 I/O 前,不必打开或关闭控制台或端口,因此此类别中没有打开或关闭例程。The console or port does not have to be opened or closed before I/O is performed, so there are no open or close routines in this category. 在 Windows 操作系统中,来自这些函数的输出始终将定向到控制台,且无法重定向。In the Windows operating systems, the output from these functions is always directed to the console and cannot be redirected.

控制台和端口 I/O 例程Console and Port I/O Routines

例程所返回的值Routine 使用Use
_cgets、_cgetws_cgets_s、_cgetws_s_cgets, _cgetws, _cgets_s, _cgetws_s 从控制台读取字符串Read string from console
_cprintf、_cwprintf_cprintf_s、_cprintf_s_l、_cwprintf_s、_cwprintf_s_l_cprintf, _cwprintf, _cprintf_s, _cprintf_s_l, _cwprintf_s, _cwprintf_s_l 将格式化的数据写入控制台Write formatted data to console
_cputs_cputs 把字符串写入控制台Write string to console
_cscanf、_cwscanf_cscanf_s、_cscanf_s_l、_cwscanf_s、_cwscanf_s_l_cscanf, _cwscanf, _cscanf_s, _cscanf_s_l, _cwscanf_s, _cwscanf_s_l 从控制台读取格式化的数据Read formatted data from console
_getch、_getwch_getch, _getwch 从控制台读取字符Read character from console
_getche、_getwche_getche, _getwche 从控制台读取字符并回显Read character from console and echo it
_inp_inp 从指定的 I/O 端口读取一个字节Read one byte from specified I/O port
_inpd_inpd 从指定 I/O 端口读取双字Read double word from specified I/O port
_inpw_inpw 读取指定 I/O 端口 2 字节的字Read 2-byte word from specified I/O port
_kbhit_kbhit 在控制台检查键击;在尝试从控制台读取前使用Check for keystroke at console; use before attempting to read from console
_outp_outp 将字节写入指定 I/O 端口Write one byte to specified I/O port
_outpd_outpd 将双字写入指定 I/O 端口Write double word to specified I/O port
_outpw_outpw 将字写入指定的 I/O 端口Write word to specified I/O port
_putch、_putwch_putch, _putwch 将字符写入控制台Write character to console
_ungetch、_ungetwch_ungetch, _ungetwch “取消获取”从控制台读取的最后一个字符,以便让它成为下一个被读取的字符"Unget" last character read from console so it becomes next character read

请参阅See Also

输入和输出Input and Output
按类别分的通用 C 运行时例程Universal C runtime routines by category