How can I gather input from a user, say "1 2 3", and put it into an array of int? So far I've tried using cin.getline() and putting the input into an array of type char. But this required me to make a char array with some value (I chose 100). To gather the numbers in this array of char I have to itterate through each element (all 100 in this case) of the array. This seems inefficient and I feel there's a better solution out there. Can anyone help? Here's my code:
#include <string>
#include <iostream>
usingnamespace std;
constint MATRIX_SIZE = 3;
constint MAX_MATRIX_SIZE = 100;
bool isRowGood(char rowValues[MAX_MATRIX_SIZE]);
int main()
{
char rowOfNumbers[MAX_MATRIX_SIZE];
cout << "Input an 3 x 3 matrix of integers to check." << endl;
cout << "Values should be entered in their 'natural'" << endl;
cout << "form, on 3 lines with 3 values per line." << endl;
cout << "[";
cin.getline(rowOfNumbers,sizeof(rowOfNumbers));
isRowGood(rowOfNumbers);
}
bool isRowGood(char rowValues[MAX_MATRIX_SIZE]){
for(int i=0; i <= MAX_MATRIX_SIZE; i++){
// This is where I stopped due to realization
// of having to loop through 100 elements for just 3 numbers.
}
returnfalse;
}
}