You print std::endl after each number. If you want to have 1 line per line, then you should print std::endl after each line. Example:
#include <iostream> int main(void) { int myArray[][4] = { {1,2,3,4}, {5,6,7,8} }; int width = 4, height = 2; for (int i = 0; i < height; ++i) { for (int j = 0; j < width; ++j) { std::cout << myArray[i][j] << ' '; } std::cout << std::endl; } }
Also note that the record using namespace std; at the beginning of your files is considered bad practice, as some user names (types, functions, etc.) become ambiguous. If you want to avoid an exhaustive prefix with std:: use using namespace std; in small areas so as not to affect other functions and other files.
source share