Sign in to follow this  
Tuss

Need some help...

Recommended Posts

Tuss    122
I have been programing for some years now, but never in c++, so i bought this book, Beginning c++ game programming by Michael dawson. I have been running trough his examples, but now i have run into a little problem. After i compile it and try to run it it just stops. I don't think it's a syntax error, but then what am i to say.. /Type test //tuss #include <iostream> using namespace std; int main () { int fuel; cout << "\nHow much fuel?"; cin >> fuel; //<----The error i think. cout << "Fuel: " << fuel << endl; std::cin.ignore(std::cin.rdbuf()->in_avail() + 1); //PAUSE return 0; } need some pointers. it's probably the cin >> fuel;

Share this post


Link to post
Share on other sites
serratemplar    1656
Your program looks just fine for me except for this:

std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);

which I admit to never having seen before. cout and cin are perfectly good for console input and output. What IDE are you running in? MSVC is really good about its console debug runs sitting there and waiting for you after you run something before it closes the console-emulation window. At least, it has been in my experience.

Try your program by remarking that line out above. I'm willing to be it will work.

Share this post


Link to post
Share on other sites
Jingo    582
Quote:
Original post by serratemplar
Your program looks just fine for me except for this:

std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);

which I admit to never having seen before.


That is fine assuming buffered input. std::cin.rdbuf() returns a pointer to the input buffer, in_avail gives you the amount of characters in the input buffer, std::cin.ignore ignores that amount of characters, plus one, so another character needs to be entered into the stream.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this