Hi, first post :cheesy:
I'm currently a complete noob to c++ programming and am currently reading the book "Beginning C++ Game Programming" written by Michael Dawson. I had the problem where i complied and ran the following source code:
#include <iostream>
int main()
{
std::cout << "Game Over!";
std::cin.ignore(std::cin.rdbuf()->in_avail() + 1);
return 0;
}
This would pop up with a window and it would then very quickly dissapear, in the book it says that this might happen and says to use the following code just before the
return 0;
bit:
std::cin.ignore(std::cin.rdbuf()->in_avail() + 1 )
This then ofcourse worked and i have to press enter to close the window that pops up (you'll see why i have written this later).
I then moved a tiny bit further into the book and used the following code:
#include <iostream>
using namespace std;
int main()
{
int score;
double distance;
char playAgain;
short lives, aliensKilled;
score = 0;
distance = 1200.76;
playAgain = 'y';
lives = 3;
aliensKilled = 10;
double engineTemp = 6572.89;
cout << "\nscore: " << score << endl;
cout << "distance: " << distance << endl;
cout << "playAgain: " << playAgain << endl;
cout << "lives: " << lives << endl;
cout << "aliensKilled: "<< aliensKilled << endl;
cout << "engineTemp: " << engineTemp << endl;
int fuel;
cout << "\nHow much fuel? ";
cin >> fuel;
cout << "fuel: " << fuel << endl;
typedef unsigned short int ushort;
ushort bonus = 10;
cout << "\nbonus: " << bonus << endl;
return 0;
}
The problem with this one is that at the red highlighted bit the user is meant to input a number into the window and press enter. I have read on this forum that you can use the following code to get around the problem:
std::cin.ignore(std::cin.rdbuf()->in_avail() + 2 )
Lo and behold it works aswell.
Now onto the real question :rolleyes:
The two following bits of source:
std::cin.ignore(std::cin.rdbuf()->in_avail() + 1 )
std::cin.ignore(std::cin.rdbuf()->in_avail() + 2 )
I have no idea what the things in them are for and how the hell it is solving the problem for me, as i have read (again on this forum) it isn't exactly good practice to wack in code and just remember not to mess up again in the future. So i was therefore wandering if you lot could tell me what the things in this mean and do so that they solve the problem so that i can use the code with actually knowing what it is doing. Considering I'm a complete noob and won't understand any real techincal jargon yet (read the book for about 3 hours now and only 20 pages in :lol: ) can you explain it in a way that even George Bush could understand. Cheers :cheesy:
IDE = Dev-C++ LINKY