insert a vector into map


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: insert a vector into map

  1. #1
    Join Date
    Jun 2008
    Posts
    1

    insert a vector into map

    I try to insert a vector consists of few items(5 items) into map

    suppose I have these vector
    1,2,3,5,1
    2,2,2,1,4
    5,5,8,4,1

    ..
    I want to insert them into map container

    what I tried to do doesn't works as definition type (here is my problem)
    struct vect
    int v;
    int w;
    int x;
    int y;
    int z;
    };


    typedef vect myVect;


    typedef std::map <myVect,int> myMap;
    typedef std::map<myVect,int>::iterator myMapiterator

    /// insert
    mymap.insert( pair<myVect,int>(vec,5) );

    can someone help how can I define a type could be inserted in map???

  2. #2
    Join Date
    Oct 2007
    Posts
    369
    What error are you getting?

    I'm sure it's an oversight in typing, but you don't have a "{" in your definition of vect.

    I *think* you want to be doing something like this:

    myVect instance = { 1, 2, 3, 4, 5 };

    mymap[5] = instance;

  3. #3
    Join Date
    Nov 2003
    Posts
    4,118
    First of all, what you have is an array, not a vector. Inserting an array into a map is possible but you need to associate each element of the array with an associated value. Alternatively, if you have a fixed sized array, you can wrap it in a class and insert objects of such class into the map using the [] operator.
    Danny Kalev

Similar Threads

  1. SQL Help
    By carbon_13 in forum Database
    Replies: 14
    Last Post: 03-14-2008, 04:03 PM
  2. how to insert data into map
    By pouncer in forum C++
    Replies: 6
    Last Post: 01-26-2006, 01:38 AM
  3. Having issues with BULK INSERT, please advise...
    By Tony Fountain in forum Database
    Replies: 4
    Last Post: 02-04-2003, 04:30 PM
  4. INSERT for multiple tables with IDENTITY
    By Kay in forum Database
    Replies: 1
    Last Post: 07-04-2001, 05:18 AM
  5. SQL Tutorial (Answer Q's & post your reply)
    By bigbastard4 in forum Database
    Replies: 2
    Last Post: 05-16-2001, 06:24 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center