简体   繁体   中英

What is the difference between iostream , stdio.h and conio.h header files in c++?

我在所有这三个头文件之间感到困惑。我在 Balagurusamy for C++ 中读到所有这些文件都用于输入和输出。但有什么区别。我知道我们使用 stdio.h 作为 scanf 和 printf,我们使用iostream 用于cin和cout。但是conio.h有什么用

stdio.h / cstdio - standard C input and output , as printf , scanf , fprintf etc. this API is a C API only and based on stateless functions and structures like FILE which hold the state. generally used in a C projects and should be avoided in C++.

iostream - standard C++ input and output, contains objects like cout , cin and cerr . works with C++ streams, which are objects that manages IO. the default IO choice for C++ projects. there is a criticism about some aspects of the C++ IO streams, but C++ IO-Streams are still the default choice for most of the projects.

conio.h - stands for "console input/output" , a Windows only header which provides C function for console IO manipulations, like getch , ungetch etc. I fail to see a modern use of this library.

The difference is actually profound. stdio talks to STDIN and STDOUT, so you can redirect output to a file or through a pipe to another program. The DOS implementation of conio does not.

Conio talks directly to the video hardware (although it may use the BIOS traps), and so it is faster, and it generally ignores terminal sequences, like ANSI escape sequences. With direct cursor control and a few other things lacking in the generic stdio, conio is much more usful for writing full screen interactive programs that use color, mouse, and line drawing symbols for GUI-like programs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM