How important is the iostream in gamedev?

Started by
7 comments, last by rip-off 11 years, 3 months ago

Hello folks :-)

I just wanna ask how important it is to learn/master the basics of iostream in c++.

eg:

cin.fail

cin.good

cin.clear

cin.bad

cin.putback

cin.get

cin.getline

cin.eof

and all that bullshit.

for me, its kinda hard to remember because i never use it when i make games, and i never use it when i test my own code (only cout and cin), but sometimes when i read books, they use it. So its getting hard and frustrating to remember how the iostream is made and when the states are set.

Advertisement

In practice, 99.9% of your usage of cin will be calling std::getline(std::cin, ...), and of cout will be simple stream operators (i.e. std::cout << "Hello, World!" << std::endl). If you stat working with actual files, you will probably be paying attention to eof() and good(), but generally not a whole lot more than that.

However, it's all useful knowledge to have, so you might as well learn it...

Tristam MacDonald. Ex-BigTech Software Engineer. Future farmer. [https://trist.am]

In practice, 99.9% of your usage of cin will be calling std::getline(std::cin, ...), and of cout will be simple stream operators (i.e. std::cout << "Hello, World!" << std::endl). If you stat working with actual files, you will probably be paying attention to eof() and good(), but generally not a whole lot more than that.

However, it's all useful knowledge to have, so you might as well learn it...

Good advice swift, I would like to expand a bit on this. "Streams" in general can be a very helpful tool in creating anything including games, the cin and cout feature families (for lack of a better term) are not the only way to handle streaming of data. In more modern cases they are actually being used less and less as coders are preferring more versatile streaming options. It is wise to have a base knowledge of streaming in general and the cin / cout feature families are a good entry level exposure to this information but I wouldn't spend excessive amounts of times learning the specifics of these two functions exactly. More so the << and >> operators and the idea that a stream is a buffered portion of memory (be it in RAM or on DISK) are the important part. When you get into file i/o and socket i/o you will find streams start making everything easier and more expandable. Beyond inter process communications (thread to thread or app to service type techniques), file streaming and socket communications there won't be many cases where streams will be very important.

Dan Mayor

Professional Programmer & Hobbyist Game Developer

Seeking team for indie development opportunities, see my classifieds post

Ok, thank you people :)

In practice, the IO stream classes aren't used much.

I've never worked on a major game where the C++ standard library IO was used (and on many projects the whole library is ignored anyways). The IO stream classes are nice for bootstrapping simple games or getting prototypes running, but heavy-duty file and socket IO, code usually needs to do things that the standard classes just don't support in any clean way.

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

On the other hand, the fstream classes with near-identical interfaces I use alot, and the sstream classes also have their occasional uses.

I'm not talking about just console IO streams. I'm talking about all of the stream classes.

Again, fstream et. al. are great for bootstrapping and code with relatively simple needs. If you want to do more sophisticated operations, such as read from memory mapped files, etc., you need to roll your own. Most people feel that the interface of the stream classes is not worth replicating once you're already writing dedicated IO code.

See also sockets, which nobody uses stream classes for in practice. Socket IO has a lot of peculiarities that the stream class abstraction cannot cleanly capture, especially when you're talking about nontrivial performance or throughput requirements.

String streams are nice for hammering out basic formatting operations, but the syntax is a pain and they lose a lot of flexibility that is mandatory in many real-world uses, such as being able to specify formatters like "The {0} smacks you with a {1} for {2} HP of damage!" (which may read very differently in a localized game and therefore not be suitable for hard-coding in a stream/operator<< style).

Wielder of the Sacred Wands
[Work - ArenaNet] [Epoch Language] [Scribblings]

Its not important to master the basics of anything until you need to use it. Learning to use classes to prepare yourself for some hypothetical future use is redundant.

It's important to learn how to find and digest documentation to figure out how to use things when you need them.

"Give a man a fire, he will be warm for a day. Set a man on fire, he will be warm for the rest of his life" - Terry Pratchett

It is good to know what exists, because that way you don't find yourself doing things the hard way due to ignorance. Of course, the balancing act then becomes how much time do you spend understanding the "existence" of something.

Even though C++'s standard library is relatively small in comparison to modern languages, there is still enough there that a beginner would have difficulty getting to the point of knowing what exists in any meaningful manner. Some of the ideas are going to be utterly foreign until you have some practical grounding in the language and computer science in general.

This topic is closed to new replies.

Advertisement