Sign in to follow this  
elitentity

Displaying MultiDimensional arrays easily

Recommended Posts

How do you display multidimensional arrays to the console? I can't seem to do it the same way as normal arrays. For example: char blah[2][2]{{'a','b'}{'c',d'}}; cout<<blah; This shows up as some wierd hexadecimal-ish thing. What I want it to show up as would be: ab cd Any idea if this is possible without too much work? Thanks

Share this post


Link to post
Share on other sites
Thanks for the help, but...
Sorry, but I am a real noob and I don't really understand that.
Here are the parts I need clarification upon:
size_x and size_y
next y and next x

edit
----------------------------------------------------------------
I looked on google and found something that might be related:
size_t and strlen? Dunno.

Share this post


Link to post
Share on other sites
Quote:
Original post by elitentity
Thanks for the help, but...
Sorry, but I am a real noob and I don't really understand that.
Here are the parts I need clarification upon:
size_x and size_y
next y and next x

just some pseudo-code, sorry for being cryptic.

size_x and size_y are the dimentions of your array, in this case, 2 by 2.

the for loops are done in BASIC style, because I like basic, dammit. [smile]

here's the C++ code

#include <iostream>
using namespace std;

int main()
{
char blah[2][2] = {{'a', 'b'}, {'c', 'd'}};

for(int y = 0; y < 2; y++)
{
for(int x = 0; x < 2; x++)
{
cout << blah[x][y];
}
cout << endl;
}
}


That should compile.

Basically, I'm looping through all the letters and printing them out. After each row, I print a return(endl) which resets it for the next row.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this