Thread: vectors

  1. #1

    Question vectors

    very confused on how to use vectors to display a matrix. Can any help with some code to start?

    template<class t>class vector

    not sure what to do after this?


  2. #2
    Registered User
    Join Date
    Aug 2001
    Ok, I'm not sure what it is you wan't help with.. displaying the content of a vector? / a 2D vector? or just generaly how a vector works?

    Here is a smal example:

    #include <vector>

    ostream& operator<<(ostream& out, const vector<int>& v) {
    copy(v.begin(), v.end(), ostream_iterator<int>(out," "));
    return out;

    int main(void) {
    // create a vector of double's, and one of int's
    vector<int> vi;

    // insert values before the beginning
    for(int i = 0; i < 10; ++i) {
    vi.insert(vi.begin(), i);

    // print out the vector
    cout << vi << endl;

    return 0;

    I'm not sure how to create a 2D(/matrix) vector .. perhaps this works:
    vector<vector<sometype>> v;

    - Anders

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Vectors
    By naseerhaider in forum C++ Programming
    Replies: 11
    Last Post: 05-09-2008, 08:21 AM
  2. How can i made vectors measuring program in DevC++
    By flame82 in forum C Programming
    Replies: 1
    Last Post: 05-07-2008, 02:05 PM
  3. How properly get data out of vectors of templates?
    By 6tr6tr in forum C++ Programming
    Replies: 4
    Last Post: 04-15-2008, 10:35 AM
  4. How to use Vector's in C++ !?!
    By IndioDoido in forum C++ Programming
    Replies: 3
    Last Post: 10-14-2007, 11:13 AM
  5. Points, vectors, matrices
    By subnet_rx in forum Game Programming
    Replies: 17
    Last Post: 01-11-2002, 02:29 PM