a program that will input an n-by-n matrix A by rows from the keyboard in the following way. Each line should input a row of the matrix where (i) one or more spaces separates each row entry and (ii) a return character follows the last digit of the last entry of each row. size parameter for the matrix should be declared as
const int maximumSize = 10;
and the matrix should be declared as
float A[maximumSize][maximumSize];but the program should NOT prompt the user for the matrix size. The program should count how many columns the user enters before hitting "Enter" and how many rows.
this is the first part of my the first c++ program and i do not know how i do this part. Please help.
in line 5, there is an error like that: variable 'std::istringstream input' has initializer but incomplete type.
i do not understand exactly why this error occur. After yor answer i realize that i did not write: include the iostream and math libraries in the program.<sorry about that :( > Is it possible the reason of the error? Thank you, for your reply.
i think i can only include iostream and math libraries. Is there a solution without <sstream> and only with iostream and math libraries? math is actually for the second part of the program, so only with iostream.
suppositions:
_ the matrix to be read is not empty
_ the input ends with a line break
1 2 3 4 5 6 7 8 9 10 11
int row=0, col=0;
do{
col=0;
while( std::cin.peek() not_eq '\n' ){ //you could also check for EOF here
std::cin >> matrix[row][col];
++col;
}
++row;
std::cin.ignore(); //discard the '\n' in the input buffer
}while( std::cin.peek() not_eq EOF );
Again thank you for your attention. your suppositions are correct. But, is your usage of do...while loop correct? I ask this question as complier expect ';' after while( std::cin.peek() not_eq '\n' ). If ı put ';' after while, what happens line 6 and 7(i think you write line 6 and 7 in while)? Also what happens line 9 and 10?
but in this, the number of row is two point more than the right, the number of col is one point more. for example for 3x3 matrix, col = 3; row = 4. Where did i mistake?