Just wondering which I/O calls you use the most - the C library calls (fopen, fread, fgets, etc), the C++ library calls (streams), or the OS-specific calls (CreateFileA etc on Windows for example)
Printable View
Just wondering which I/O calls you use the most - the C library calls (fopen, fread, fgets, etc), the C++ library calls (streams), or the OS-specific calls (CreateFileA etc on Windows for example)
Pfft.. I wanted to see whether C++ users preferred the standard C i/o call or the OS ones instead of the standard C++ calls, but oh well, never mind...
Personally however, I think the C++ I/O library sucks for anything but the most basic of operations. I prefer the OS calls myself.
option 2, please.
I'm an avid user of C++, but I prefer C's I/O routines. C++ routines can be slow, and they are overcomplicated solutions to simple problems. cout<< and cin>> are the only ones I ever use, and I rarely use them. printf() for me.
Fstream is terrible, IMHO. I've had so many problems trying to work it to do what I want it to do. I've heard that C's file i/o is faster as well, but I don't notice a speed difference between cstdio and fstream.
i use the c++ stuff... idk... it just seems easier to me... probably because I learned them first...
I haven't had a whole lot of experience with C-style I/O, but C++ streams work just fine for me.
I would agree that C++ streams are complicated, but not overcomplicated. Honestly, all I/O operations are slow, comparitively. If I wanted to make a streamline I/O routine where every millisecond was precious, I would probably use C-style I/O. But for normal I/O, I'll take the stream object.Quote:
C++ routines can be slow, and they are overcomplicated solutions to simple problems
I'd use the OS specific calls as they are the fastest.Quote:
Originally posted by PorkyChop
If I wanted to make a streamline I/O routine where every millisecond was precious, I would probably use C-style I/O.
For simple things I use cout but if I want anything formatted, I tend to use printf(), acheiving the same results with manipulators is not difficult, but takes up so much space. That said, I mostly program Windows, so neither is of any direct use, but then I tend to use sprintf() when building strings.
OS I/O is not portable. C++ I/O is much easier to use than C I/O. Is one slower than the other? Probably. But keep in mind that nowadays software is more expensive and valuable than hardware. It's a better use of resources to write a program that's easy to write than one that worries about some miniscule speed optimization. The fact remains that the user will not be able to distinguish the difference, however one is more difficult to code than the other.
OS calls are not portable, better would be to use POSIX calls instead, or standard C/C++ calls. Depending on the type of application I use POSIX calls or standard C/C++ calls.
As most of the coding I do is very windows oriented....I tend to use CreateFile/ReadFile/WriteFile more than anything else