LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   Vectors in C++ (https://www.linuxquestions.org/questions/programming-9/vectors-in-c-119177/)

sabeel 11-23-2003 10:43 AM

Vectors in C++
 
Hi
I wanted to know how i could implement an Array of vectors (each vector holding a pointer to an object).
can someone point me to some webpages.


thanks in advance
sabeel

MartinN 11-23-2003 11:52 AM

You probably want to use the vector class from the Standard Template Library (STL). STL has ready-made classes for most types of containers and they are used in a consistent way. A good reference to the STL is here:
http://www.dinkumware.com/refxcpp.html

Exactly what do you want to do? You seem to be a little confused. Do you want a vector where every element is a pointer to an object?

Regards
Martin

megaspaz 11-23-2003 12:00 PM

do you already know how to use vectors? if you do, then you can use a vector of vectors or if you know how map works, you can make a map of vectors.

one way is to basically define your vector types using typedef:

Code:

#include <string>
#include <vector>

using namespace std;

typedef vector <string> s_vector;
typedef vector <s_vector> vs_vector;

int main ()
{
    s_vector my_string_vec;
    vs_vector my_vec_of_string_vec;

    //do stuff like pushback strings into my_string_vec and
    //and then pushback string vectors into my_vec_of_string_vec.  yada yada yada
    return 0;
}

basically first typedef a vector of strings (in the example above called s_vector) and then typedef a vector of s_vectors (here called vs_vectors). you can then typdef yourself some string and vector iterators to navigate through the strings and vectors if you want, but both of those containers can be navigated using subscripts.

anyway, i don't know of any online stuff except for maybe this: http://www.research.att.com/~bs/C++.html since i use his book for reference mainly:

http://www.research.att.com/~bs/3rd.html

nice basic examples of the c++ stl containers and a nice look into the specifications of such containers.


All times are GMT -5. The time now is 09:15 PM.