• Welcome to Valhalla Legends Archive.
 

vector in C++

Started by touchstone, January 15, 2004, 02:21 PM

Previous topic - Next topic

touchstone


vector<int> row;
vector< vector<int> > temp;
vector< vector< vector<int> > > matrix;

// initialize row
for (int x = 0; x < 10; ++ x)
row.push_back(x);
temp.push_back(row);
temp.push_back(row);
matrix.push_back(temp);



// how can i print this matrix???
do i need any STL display function????

is it possible to use typedef here?? how?

i wrote ....to see the content of the matrix


for(int i=0; i < matrix.size(); ++i) cout << matrix << endl;


but i am getting wrong garbage values....

how do i print the matrix??

Skywing

#1

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;



vvi matrix;
/* initialize here ... */
for(int i = 0; i < matrix.size(); i++)
for(int j = 0; j < matrix[i].size(); j++)
 cout << "(" << i << ", " << j << ") == " << matrix[i][j] << endl;

Add more inner loops for each dimension/subscript.

touchstone

hi

its not working ... i wrote



#include<vector>
#include<stdio.h>

int main()


{
 typedef vector<int> row;
 typedef vector<row> temp;

 row R1;
 temp T1;

 for (int x = 0; x <3; ++ x)
 R1.push_back(x);
 T1.push_back(R1);
 T1.push_back(R1);
 matrix.push_back(T1);


for(int i = 0; i < matrix.size(); i++)
for(int j = 0; j < matrix[i].size(); j++)
printf("%d ", matrix[i][j]);


}




no its not working....giving compilation error

Kp

While I generally don't offer solutions to people who complain about compile errors and don't supply the error text, I will in this case.  You need to declare matrix if you plan on refering to it!
[19:20:23] (BotNet) <[vL]Kp> Any idiot can make a bot with CSB, and many do!