Hi, I'm quite new at C++ and I'm having a problem that's been bugging me for awhile now. I want to read a bunch of numbers like so: 1,2,1,4,5,6
If I input the above like so: "1 2 1 4 5 6", (while commenting the cin>>junk, it works perfectly. Whenever I try to use commas, however, the program crashes. If anyone could tell me why, I'd be grateful. Here's my input code:
Thank you.Code:void input() { int x=0; int player[20]; //Array - Player statistics int enemy[20]; //Array - Enemy statistics int dice[3]; //Array - Dice int size=0; //Number of squares with markers (player) int size2=0; //See above, but for enemy char junk; //Takes in the junk commas in the input for(x=0;x<20;x++) //Sets all elements of the array equal to zero. { player[x]=0; enemy[x]=0; } cout<<"\n\nInput: "; cin>>player[0]; size = player[0]*2; for(x=1;x<=size;x++) //Sets player's numbers (inputted) { cin>>junk; cin>>player[x]; } cin>>junk; cin>>enemy[0]; size2 = enemy[0]*2; for(x=1;x<=size2;x++) { cin>>enemy[x]; cin>>junk; } for(x=0;x<3;x++) { if(x!=2) { cin>>dice[x]; cin>>junk; } else { cin>>dice[2]; } } //I call another function and I do close the brackets to void-function input down here eventually.