The sample input to my code is:
{ 1, 2, 3, 4 }
I wish to ignore the curly brackets and commas, and read the numbers into an array.
Hmmm, this might work:
// Ignore all characters up to and including the open curly bracket
cin.ignore(100000, '{');
// Read the numbers into an array
int my_array[4];
unsigned int array_index = 0;
cin >> my_array[array_index];
array_index++;
cin >> my_array[array_index];
array_index++;
cin >> my_array[array_index];
array_index++;
cin >> my_array[array_index];
// Ignore all characters up to and including the newline.
cin.ignore(1000000, '\n');
You could use a for
loop to read in the numbers.