STL: doubly array's x[n][n]
I need help making a double array. I believe you can do it by doing something like
vector(vector(int)) which would make a vector of a vector of int's.
What I want to do is have the power of vector but also be able to access the members like this
x[10][2] = 4;
is that possible? If not vector anything else in the STL?
If it is possible can you give me a small example to look at?
EDIT: html tags messed up my code.. all > and < are now ) and (
[edited by - Whoknewb on January 26, 2003 3:07:29 PM]
#include <vector>using namespace std;typedef vector<vector<int> > IntVector2D; // with a space between the >> otherwise it is parsed as a right shift.int rows = 10, columns = 20;IntVector2D myvec( rows, vector<int>( columns ) );myvec[5][10] = 1000;
For more details, refer to your C++ manual.
[ Start Here ! | How To Ask Smart Questions | Recommended C++ Books | C++ FAQ Lite | Function Ptrs | CppTips Archive ]
[ Header Files | File Format Docs | LNK2001 | C++ STL Doc | STLPort | Free C++ IDE | Boost C++ Lib | MSVC6 Lib Fixes ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
That worked great Fruny but I''m having more problems now with resize function.
Data.resize(y, vector(x));
That only sort of works. It resizes the y value but doesn''t resize to the new x value.
Data.resize(y, vector(x));
That only sort of works. It resizes the y value but doesn''t resize to the new x value.
int rows = 10, columns = 20; for(IntVector2D::iterator c = myvec.begin(); c != myvec.end(); ++c) c->resize(columns); myvec.resize(rows, std::vector<int>(columns));
Chess is played by three people. Two people play the game; the third provides moral support for the pawns. The object of the game is to kill your opponent by flinging captured pieces at his head. Since the only piece that can be killed is a pawn, the two armies agree to meet in a pawn-infested area (or even a pawn shop) and kill as many pawns as possible in the crossfire. If the game goes on for an hour, one player may legally attempt to gouge out the other player's eyes with his King.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement