I’m testing my roulette classes but visual studio don’t let me see the output since cin.ignore() does not work, and I have no idea what going on here,
can you explain why my cmd line window disapear and why cin.ignore() in this code never gets invoked?
Thank you so much!
#include "Bet.h"
#include "Table.h"
#include <iostream>
using namespace std;
using namespace Roulette;
int main()
{
cout << "Enter numbers for Split bet:" << endl;
short answer;
vector<short>* Selection = new vector<short>;
for (short i = 0; i < 2; ++i)
{
cin >> answer;
Selection->push_back(answer);
}
cout << "Enter how many chips and chip worth:" << endl;
short chips, worth;
cin >> chips >> worth;
Bet* MyBet = new Bet(TableLayout::European, BetName::Split, chips, worth, Selection);
Bet* Complex = new Bet(TableLayout::European, BetName::VoisinsDeZero, 1, 1);
Complex->PrintProperties();
cin.ignore(); // THIS IS IGNORED!!! WHY??? please...
delete Selection;
Selection = nullptr;
delete Complex;
delete MyBet;
return 0;
}
EDIT:
I press F5 to run a program and then type in the numbers as follows:
1 enter
2 enter
1 enter
1 enter
and here cmd goes away, program skips cin.get() ( or cin.ignore() ) whatever it doesn’t work.
On this line, for example, if you type the last
1and press enter, A\nis still left in the stream unread.When you do
cin.ignore();, it extracts the leftover character and the program finishes. Changecin.ignore();tocin.ignore(2);and it should work.