PDA

View Full Version : 2D string arrays C++ .NET 2003


Afrow UK
07-17-2005, 05:04 PM
I'm having real trouble with this.

I assumed that
char *myArray[10][10] would make a 10 row array each with 10 columns. However it just makes a single dimension array of 10 rows that can have 10 characters in each.

How can I go about having a 2D array of 10 rows and 10 columns?
<vector> doesn't seem to exist, nor System array and MSDN only seems to reference standard C++.
I also do not have the manual that should come my Visual Studio 2003 (for some reason it wouldn't install).

Cheers

-Stu

Dr. Evil
07-17-2005, 08:59 PM
Are you trying to create a 10 by 10 2D array of strings? In that case just create a 3D array, or dynamically allocate memory for one.

char arr[10][10][50];

Afrow UK
07-17-2005, 09:10 PM
So how would I assign a string (char *) to say row 9, col 0?

This brings up an error:
mainArray[arrayCount][0] = (char *[1024])szArrayName;
"d:\Program Files\Nsis\Contrib\NSISArray\NSISArray.c(27): error C2067: cast to array type is illegal"

Or:
mainArray[arrayCount][0] = szArrayName;
"d:\Program Files\Nsis\Contrib\NSISArray\NSISArray.c(27): error C2106: '=' : left operand must be l-value"

arrayCount == 0

-Stu

Afrow UK
07-18-2005, 01:15 AM
I have found that lstrcpy seems to do the trick, although I'm not sure if it's safe but it seems to work perfectly.

lstrcpy((LPTSTR)mainArray[iArrayIndex][iIndex], szValue);

-Stu