I know how to declare a 1D vector like below but how do you declare a 2D vector ?

``List<String^>^ Vec1 = gcnew List<String^>();``

Actually, that is a list, not a vector. Minor differences, but still.
Here's one way (matrix of strings):

``````typedef vector<string> row;

vector<row> *vec1 = new vector<row>;``````

Actually, that is a list, not a vector. Minor differences, but still.
Here's one way (matrix of strings):

``````typedef vector<string> row;

vector<row> *vec1 = new vector<row>;``````

That's not managed code, but managed code is probably something similar.

Thanks, a list it is but this declaration of a 2D vector in the previous post is this really for the System::IO namespace.

I know how to declare a 2D vector in the std:: namespace like this wich should be something simular to that:

``````typedef std::vector<string> String1D;
typedef std::vector<String1D> String2D;``````

Is it possible to do the below to a 2D for the System::IO namespace. I am not really sure here.

``List<String^>^ Vec1 = gcnew List<String^>();``

Actually, that is a list, not a vector. Minor differences, but still.
Here's one way (matrix of strings):

``````typedef vector<string> row;

vector<row> *vec1 = new vector<row>;``````

It's exactly the same:

``List<List<String^>^>^ vec = gcnew List<List<String^>^>();``

Don't forget to use gcnew for each of the sublists too, and feel free to simplify the syntax using typedef as has already been shown.

I have come up with this code where I am creating a 2D list.
Then within a loop I think I am declaring 1000 elements to each dimension wich in the end
will have List.
However when I run the program, I will have an errormessage that says the below so there is something that I might doing wrong.
'Object reference not set to an instance of an object'

``````typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{
for( int i = 0; i < 1000; i++ )
{
}

}

List1 = "Hello";``````
``````typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{
Vec1 Row;
for( int i = 0; i < 1000; i++ )
{
}

}

List1 = "Hello";``````

It should be something like this :)

Thanks Sci@Phy but if I run the program with the below code, I will still have the same Errormessage:) It seems that elements is Added but wonder what is being wrong.

'Object reference not set to an instance of an object'

``````typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{
Vec1 Row;
for( int i = 0; i < 1000; i++ )
{
}

}

List1 = "Hello";``````

I have also tried this approach to declare elements in the 2 Dimensions but with the same Error.

``````typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{

for( int i = 0; i < 1000; i++ )
{
List1[j]->Add("0"); //I suppose I fill the First Dimension with 1000 elements
}

}``````

I have tried this approach to declare elements in the 2 Dimensions but with the same Error.
'Object reference not set to an instance of an object'

``````typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{

for( int i = 0; i < 1000; i++ )
{

}``````

Correct me if I'm wrong, but doesn't the cavet ^ symbol in C++.NET mean that the type is actually a pointer?

``List1.Add(Vec1());``

looks fishy... Vec1 is a pointer-type, so doesn't that mean you need to call gcnew to properly instantiate that Vec? O_O

``List1.Add(gcnew Vec1());``

I'd assume.

When using pointers in .NET, you do use * and & to address pointers so the cavet ^ symbol should only meen a type as int and double I beleive like string for the std:: and then String^ for managed.
If I put gcnew before Vec1 in the code below the compiler says this message:

'Vec1' : cannot use this type as argument of 'gcnew'

``````typedef List<String^>^ Vec1;
typedef List<Vec1> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{

for( int i = 0; i < 1000; i++ )
{
}

}``````

I think you are after ...

``````typedef List<String^> Vec1;
typedef List<Vec1^> Vec2;

Vec2 List1;

for( int j = 0; j < 1000; j++ )
{

for( int i = 0; i < 1000; i++ )
{
}
}``````

Mitrmkar,

Thank you! Now it works...

When compiling the below code I will have a compileerror that says:
String3D : illegal use of this type as an expression
String2D : illegal use of this type as an expression
String1D : illegal use of this type as an expression

I wonder if I doing this correct when trying to iterate through all 3 Dimension with .Count ?

``````typedef List<String^> String1D;
typedef List<String1D^> String2D;
typedef List<String2D^> String3D;

String3D Dimensions;
int count1 = 0;
int count2 = -1;

for( int i = 0; i < 5; i++ )
{

if( i == 0 )
{
}
if( i >= 0 && i <= 4 )
{
count2 = count2 + 1;
}
}

for(int h = 0; h < String3D.Count; ++h)
{
for(int j = 0; j < String2D.Count; ++j)
{
for(int k = 0; k < String1D.Count; ++k)
{
}}}``````

I found out that "()" was needed. When iterating through the dimensions to show the "TextString" that was put into the List(Dimensions), only 1 MessageBox will appear.
As I have put "TextString" to 5 elements it should be 5 Times.

I am putting the string to these elements:
Dimensions;
Dimensions;
Dimensions;
Dimensions;
Dimensions;

``````typedef List<String^> String1D;
typedef List<String1D^> String2D;
typedef List<String2D^> String3D;

String3D Dimensions;
int count1 = 0;
int count2 = -1;

for( int i = 0; i < 5; i++ )
{

if( i == 0 )
{
}
if( i >= 0 && i <= 4 )
{
count2 = count2 + 1;
}
}

for(int h = 0; h < String3D().Count + 1; ++h)
{
for(int j = 0; j < String2D().Count + 1; ++j)
{
for(int k = 0; k < String1D().Count + 1; ++k)
{

MessageBox::Show(Dimensions[h][j][k]);

}

}}``````

What I try to find, is the equavilent to the vector ::iterator for the first code.
The first code iterates each Dimension from .begin() to the .end() and then continues
to next dimension for the 3 Dimensions.

``````typedef std::vector<string> String1D;
typedef std::vector<String1D> String2D;
typedef std::vector<String2D> String3D;

String3D Dimensions;

for (String3D::iterator i = Dimensions.begin(); i != Dimensions.end(); ++i)
{
for (String2D::iterator j = i->begin(); j != i->end(); ++j)
{
for (String1D::iterator k = j->begin(); k != j->end(); ++k)
{}}}``````

As all these Dimensions below for "List" have been ->Add and therefore have different many elements for each Dimension, I am looking for the same(equavilent) method to Iterate each Dimension to the end as the above approach for the std::vector.
Something might be missing in the below code.

``````typedef List<String^> String1D;
typedef List<String1D^> String2D;
typedef List<String2D^> String3D;

String3D Dimensions;

for(int i = 0; i < String3D().Count + 1; ++i)
{
for(int j = 0; j < String2D().Count + 1; ++j)
{
for(int k = 0; k < String1D().Count + 1; ++k)
{}}}``````

In some way it is needed to refer to the previous vectordimension.
The problem is that I dont know how you refer to the previous dimension beginning and end and set this to some sort of an iterator as this is put ?

String2D::iterator j = i->begin(); j != i->end(); ++j

For the List, I cant find either a begin or end member or iterator.
The below code could be a step closer perheps.
Any idéas or tips would be of help. I am quite stuck.

``````for(int i = 0; i < Dimensions.Count; ++i)
{
for(int j = 0; j < String3D().Count; ++j)
{
for(int k = 0; k < String2D().Count; ++k)
{
}}}``````

Yes, this was the thread I was reading on but I missed it and as I saw it was as simple as this. I was imagining me something different.
It helped alot. Great !

``````for(int i = 0; i < Dimensions.Count; ++i)
{
for(int j = 0; j < Dimensions[i]->Count; ++j)
{
for(int k = 0; k < Dimensions[i][j]->Count; ++k)
{

MessageBox::Show(Dimensions[i][j][k]);

}

}
}``````