How do I fill the array with keyboard input through a loop so that when assigning an array of values ​​to the elements and pressing Enter, the cursor does not move to the next line? I need him to move to a new line only when all the elements of this line are filled. I hope I clearly stated the problem. Here is a piece of code.

for (int i = 0; i < m; ++i) { for (int j = 0; j < n; ++j) { cin >> ar[i][j]; } cout << endl; } 
  • Moving the cursor through the console window depends on the OS in general, so it is worth mentioning it in the question. Cross-platform task, I think, can be solved using ncurses. Or refuse to press Enter has not yet entered the entire line. And the elements in the line to enter through a space. - αλεχολυτ

1 answer 1

 int a[5]; for (int i = 0; i < 5; i++) cin >> a[i]; 

something like this, just for a multidimensional array to remake. write single line elements separated by a space