2 dimensional array problem

I'm doing a pretty tedious code that involves using 2d arrays, however I'm really not sure how to make the actual columns for the array, especially since they are character columns. The array is declared as a char but I'm confused if I need to declare the columns individually or use a loop. Does anyone know?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// Example program
#include <iostream>
#include <string>
using namespace std;

int main()
{
    char arr[8][8];
    for(int k = 0; k < 8; k++){
        for(int i = 0; i < 8; ++i){
            arr[k][i] = 'a';
            cout << arr[k][i] << " ";
            
        }   
    }

    return 0;
}


This is how you need to declare a two dimentional array of char.



Note: You do not have to do this! If you are interested, you can use this feature:
In c++ 11 and 14 you can you enumeration, which is an enum class, that is of type char, and you can write char variables inside.

1
2
3
4
5

enum class names : char {
  v1 = 'a' , v2 = 'b' , variable3 = 'c'   // no semicolon!
};   // semicolon


This helps you to for example assign the two dimentional array of arr[0][i] = v1 and arr[1][i] = v2 , etc.

Look into it further if you are interested.
Last edited on
Alright thank you I will give it a shot.
Topic archived. No new replies allowed.