How to print 2D Arrays in C++?

前端 未结 3 2036
轮回少年
轮回少年 2020-12-03 12:23

I am trying to print a text file out on screen using arrays, but I\'m not sure why it does not appear the way it is in the text file.

The text file:

         


        
3条回答
  •  情深已故
    2020-12-03 13:02

    you can do it like this

    #include 
    
    int your_array[2][4] = { 
      {1,2,3,4}, 
      {5,6,7,8}  
    };
    
    using namespace std;
    
    int main() {
    
        // get array columns and rows
          int rows =  sizeof your_array / sizeof your_array[0]; 
          int cols = sizeof your_array[0] / sizeof(int); 
          
          // Print 2d Array
         cout << "your_array data "<

    output

    1
    2
    3
    4
    5
    6
    7
    8
    

提交回复
热议问题