cin.ignore();

Hi!

I've been doing C++ for 2 days now and love it. I'd like to know what these lines do. Also, what are 'game loops'? Can someone please explain this in-depth. I'd appreciate an answer! :P

1
2
cin.ignore();
cin.get();
Those two lines both do something similar: they get a single character from cin and throw it away.

This is a common effort to make sure the input stream is properly synchronized to the number of times the user has pressed the ENTER key.

getline() reads an entire line of text and the ENTER key (which it tosses)

cin >> foo only reads a foo, nothing more. So you must get() or ignore() the ENTER key.



A "game loop" is the same as an "event loop". All 'normal' GUI programs operate by waiting for something to happen, then calling the appropriate routine to handle it. When you write a game, you need to do this yourself, because the way you respond to events will differ depending on your game.

More reading:
http://en.wikipedia.org/wiki/Event_loop
http://www.sfml-dev.org/tutorials/2.0/window-events.php

Hope this helps.
Thank you! This helped a lot. :)
Topic archived. No new replies allowed.