Just out of curiosity, how does iostream access the input-output system. (I have a bad habit of constantly reinventing the wheel, and I'm wondering if I can build a custom input-output system to the likes of iostream).
相关问题
- Sorting 3 numbers without branching [closed]
- How to compile C++ code in GDB?
- Why does const allow implicit conversion of refere
- thread_local variables initialization
- What uses more memory in c++? An 2 ints or 2 funct
相关文章
- 放在input的text下文本一直出现一个/(即使还没输入任何值)是什么情况
- Class layout in C++: Why are members sometimes ord
- How to mock methods return object with deleted cop
- Which is the best way to multiply a large and spar
- C++ default constructor does not initialize pointe
- Selecting only the first few characters in a strin
- What exactly do pointers store? (C++)
- Converting glm::lookat matrix to quaternion and ba
All streams go to a streambuf. That streambuf will depend on the type of stream. An ofstream goes to a fstreambuf; cout goes to some unspecified streambuf. If you want to customize things, cout allows you to get this streambuf and possibly replace it.
A common pattern is the "filtering streambuf", which is a streambuf interface that transforms its input before sending it to another streambuf. This can be combined with cout: take out the original streambuf, wrap that in a filtering streambuf, and put that wrapper back in cout. You don't need to know how the original streambuf works.
For a detailed guide to IOstreams, see the book Standard C++ IOStreams and Locales. After reading it I suspect you will be content to manage with with the status quo - IOStreams are probably the most complex part of the C++ standard library.
You certainly could reinvent the wheel.
There are a lot of complications added to the stream operators to handle international character sets. After having looked at it reasonably deeply I really didn't care for it much. It's very complicated and completely destroys any chance of easily using inheritance. It works and is available though. (I wanted to change the behavior of the storage it uses during conversions)
It depends...
It somehow interacts with the native IO system of the operating system. It might internally use the C library, which uses system calls to the kernel, or it might use system calls directly. The exact implementation is highly dependent on the platform.
Many people will say don't reinvent the wheel, but it could be a good learning experience. If you are using Windows, look into the Win32 API calls for file handling. If you use Linux, either use the POSIX/C library, or use the system calls (much harder, I would suggest going with the C library).