Jump to content

  • Log In with Google      Sign In   
  • Create Account

How important is the iostream in gamedev?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Assassinbeast   Members   -  Reputation: 271

Like
1Likes
Like

Posted 15 January 2013 - 10:01 AM

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.



Sponsor:

#2 swiftcoder   Senior Moderators   -  Reputation: 10363

Like
5Likes
Like

Posted 15 January 2013 - 10:23 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...


Tristam MacDonald - Software Engineer @Amazon - [swiftcoding]


#3 Dan Mayor   Crossbones+   -  Reputation: 1714

Like
4Likes
Like

Posted 15 January 2013 - 11:01 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.


Digivance Game Studios Founder:

Dan Mayor - Dan@Digivance.com
 www.Digivance.com


#4 Assassinbeast   Members   -  Reputation: 271

Like
0Likes
Like

Posted 15 January 2013 - 12:44 PM

Ok, thank you people :)



#5 ApochPiQ   Moderators   -  Reputation: 16387

Like
4Likes
Like

Posted 15 January 2013 - 12:56 PM

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.

#6 Servant of the Lord   Crossbones+   -  Reputation: 20982

Like
2Likes
Like

Posted 15 January 2013 - 01:35 PM

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


It's perfectly fine to abbreviate my username to 'Servant' rather than copy+pasting it all the time.
All glory be to the Man at the right hand... On David's throne the King will reign, and the Government will rest upon His shoulders. All the earth will see the salvation of God.
Of Stranger Flames - [indie turn-based rpg set in a para-historical French colony] | Indie RPG development journal

[Fly with me on Twitter] [Google+] [My broken website]

[Need web hosting? I personally like A Small Orange]


#7 ApochPiQ   Moderators   -  Reputation: 16387

Like
7Likes
Like

Posted 15 January 2013 - 02:00 PM

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).

#8 Aardvajk   Crossbones+   -  Reputation: 6182

Like
3Likes
Like

Posted 16 January 2013 - 07:53 AM

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

Edited by Aardvajk, 16 January 2013 - 07:54 AM.


#9 rip-off   Moderators   -  Reputation: 8709

Like
3Likes
Like

Posted 16 January 2013 - 08:43 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS