Thread: load matrix into a vector of vectors

  1. #1
    Registered User
    Join Date
    Jun 2006

    load matrix into a vector of vectors


    is there an efficient for to insert the elements of a 2d array into a vector of vectors?
    I have
    	vector< vector <int> >  Points
    	for (i = 0; i < n; i++ )
            int Matrix[n][d];
            //populate matrix....
            //How to load the data in the Matrix into the vector of v. Points?
            // is there something better than
            //iteratation through:
            Points[i][j] = Matrix[i][j]
    thanks for the help

  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    You could use iterators, but that would be basicly the same thing.

    You might be able to find a vector constructor to simplify things; from
    Constructors and destructors
    vector<T> v; L
    Creates an empty vector of T's.
    vector<T> v(n);
    Creates vector of n default values.
    vector<T> v(n, e); L
    Creates vector of n copies of e.
    vector<T> v(beg, end); L
    Creates vector with elements copied from range beg..end.
    v.~vector<T>(); L
    Destroys all elems and frees memory.
    My suggestion is to replace the code that "populates matrix" with code that populates Points, if possible.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. C - access violation
    By uber in forum C Programming
    Replies: 2
    Last Post: 07-08-2009, 01:30 PM
  2. Matrix Help
    By HelpmeMark in forum C++ Programming
    Replies: 27
    Last Post: 03-06-2008, 05:57 PM
  3. What is a matrix's purpose in OpenGL
    By jimboob in forum Game Programming
    Replies: 5
    Last Post: 11-14-2004, 12:19 AM
  4. Matrix and vector operations on computers
    By DavidP in forum A Brief History of
    Replies: 11
    Last Post: 05-11-2004, 06:36 AM