I am working on program that would calculate with matrixes but i am not sure what is best way how to read matrix line by line from command line.
My goal is this:
Please enter number of lines:
2
Please enter line 1/2:
1 4 5 2
Please enter line 2/2:
1 5 7 8
At the end of this i would like to have array or vector of numbers 1,4,5,2,1,5,7,8.
This is my code:
vector<string>matrix;
string input;
int nrows;
cout << "Enter number of rows:" << endl;
cin >> nrows;
getline(cin, input);
for (int i = 1; i <= nrows; i++) {
cout << "Enter line " << i << "/" << nrows << endl;
getline(cin, input);
matrix.push_back(input);
}
for (int i = 0; i < matrix.size();i++){
cout << matrix.at(i)<<endl;
}
This reads whole line and save it into vector of string and there is much to do to separate just numbers. Is there any way how could I load only numbers in the line ? So for example for the line:
1 a 3 2 4sdsd
I would get numbers 1,3,2,4 ?
Thank for any help.