![]() |
|
#1
|
||||
|
||||
2D vectoranyone know how to create a 2D vector,
can give an example how to create it, and how to inside the data inside the 2D vector like: 1 2 3 4 5 6 7 8 9 3 column and 3 row. thx :-) __________________
challenges are make life interesting, overcome them is make life meaningful. |
|
#3
|
||||
|
||||
|
2D array i know
but i want know how to create 2D vector and also want know how to insert data inside the 2D vector. we need include <vector>, for example CPP / C++ / C Code:
can u help me dsmith Last edited by dsmith : 15-Feb-2004 at 08:09.
Reason: Added c syntax highlighting.
|
|
#4
|
||||
|
||||
|
Quote:
Tay, you have found my major weakness! I hope that someone else can help you, because I am illiterate in most of the C++ stuff. If no one else posts, I will look into it, but I really know nothing about this... |
|
#5
|
||||
|
||||
|
i thought c also got vector
__________________
challenges are make life interesting, overcome them is make life meaningful. |
|
#6
|
|||
|
|||
|
You can create types that contain 2 ints, like this:
CPP / C++ / C Code:
This is declared as: CPP / C++ / C Code:
This is a new type, which you can tell the vector class to use. See if you can figure out how you can use this via vector template. This is C, in C++ I'd create a coord class with 2 public variables x & y (or even better, public functions which alter the private variables) which can also be used in the vector class. GF |
|
#7
|
||||
|
||||
|
let say i want make 50 x 50 square
what to do it mean column 50 , row also 50 __________________
challenges are make life interesting, overcome them is make life meaningful. |
|
#8
|
|||
|
|||
|
Oh, that's a matrix. There is no premade matrix class sadly (although there's plenty on the net). But they're not hard to code, if you're well up on pointers. www.gidforums.com.
This is purely C: CPP / C++ / C Code:
C++ has a far nicer way of playing with matrices. You can create a Matrix object, and tell it how big to be, and set it's values easily. But it requires writing all that yourself, but it's not too tough. GF Last edited by Garth Farley : 17-Feb-2004 at 11:56.
Reason: Left brain at home
|
|
#9
|
|||
|
|||
|
However, the code I've just posted doesn't do what vector can. Vector is a linked list, where you can add new links all the time. Above once you've called calloc, a chunk of memory is allocated. This won't expand dynamically without shedloads of nasty stuff, and isn't worth it. So you#ve to be sure how big you want the array before you call calloc.
Hmmm, I'm wondering if it's possible to make a vector of vectors? GF |
|
#10
|
|||
|
|||
2D Vector SampleI see this thread is a little old, and you have probably already solved your problem, but this may help someone.
CPP / C++ / C Code:
Quote:
Last edited by kzutter : 05-May-2004 at 16:04.
Reason: C++ tags
|
Recent GIDBlog
Observations of Iraq by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Why error? | eye | C++ Forum | 0 | 18-Jan-2004 03:25 |
| 'stuct' instead of just 'int' | mediaware2002 | C++ Forum | 1 | 08-Jan-2004 09:33 |
| vector prob | nattylife | C++ Forum | 1 | 15-Nov-2003 07:41 |
| vector sorting | gotnospoon | C++ Forum | 0 | 10-Nov-2003 15:26 |
| C++, Matrix Max Length | calculus87 | C++ Forum | 2 | 15-Sep-2003 07:08 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The