Under what conditions should I use io.h for windows.h?

I am working on a project related to system programming in Windows. For this, I pointed to windows.h . Now I met io.h What is the difference between the two?

For example, since I am transferring an application that has already been deployed on Linux, the file open function is open , and on Windows, if I use windows.h , the file open function will be CreateFile , and if I use io.h , it will be _open () .

+6
source share
3 answers

io.h initially provided declarations for low-level input / output primitives in Unix and related constants and the like. Since quite a bit of code depended on it, many (most?) Compilers for other systems provided a header with the same name and some library functions that worked (at least mostly), as on Unix.

Windows.h is a (kind of) crude counterpart for Windows - a header that provides access to (declarations) for functions, constants, etc. for windows. The big difference is that Windows.h does a lot more than the basic low-level I / O covered by io.h , instead covering all the GUI functions, etc.

So: if you want to write code that does I / O at a fairly low level on Unix-like systems and can also be ported to other systems like Windows, you probably want to use io.h If you want to do system programming specifically for Windows, you will almost certainly want to use windows.h .

+6
source

Ultimately, all of these various I / O functions on the Windows map trigger calls in the Win32 API (e.g. CreateFile for your specific question). So, if you want to use this API directly, prefer windows.h. If you want to use various (compatible) wrappers, be it standard C ++ lib, standard IO lib, POSIX subsystem, etc., then you can use other include files.

+4
source

If you are trying to write portable code, you should use stdio.h .

Windows.h includes all the headers needed to create a Windows application (all the main Win32 API headers and preprocessor directives). If you are just looking to read / write files and want to make it portable, this is not the header file that you would choose.

+4
source

Source: https://habr.com/ru/post/958318/


All Articles