assigning multiple elements to a vector?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: assigning multiple elements to a vector?

  1. #1
    Join Date
    Jul 2005
    Posts
    22

    assigning multiple elements to a vector?

    Does anyone know whether there is a way to assign multiple copies of an element to the end of an STL vector? I mean succintly ... of course you can use a for loop and the push_back function ... is there a way to assign multiple copies of a element to the end of a pre-existing vector though? I thought the assign function did that but it over writes what is already in it. Any help appreciated as usual ...

    (btw: does anyone post replies on this forum other than Danny? I would but I'm afraid I don't know enough to be helpful w/ most of the posts I read)

  2. #2
    Join Date
    Nov 2003
    Posts
    4,118
    Quote Originally Posted by bpw1621
    Does anyone know whether there is a way to assign multiple copies of an element to the end of an STL vector? I mean succintly ... of course you can use a for loop and the push_back function ... is there a way to assign multiple copies of a element to the end of a pre-existing vector though? I thought the assign function did that but it over writes what is already in it. Any help appreciated as usual ...
    You probably mean assign()? Look at this member function. It has severa overloaded versions but the bottom line is this: it assigns to a sequence of elements in a vector (or a similar container) at once. Another technique is using stream iterators but it's not as intuitive as calling assign(). See:
    http://www.devx.com/getHelpOn/10MinuteSolution/20410

    Quote Originally Posted by bpw1621
    (btw: does anyone post replies on this forum other than Danny? I would but I'm afraid I don't know enough to be helpful w/ most of the posts I read)
    Of course there are other people replying; it's just that I have to have the last word;) Seriously, there are many regular members here who post replies every day.
    Danny Kalev

  3. #3
    Join Date
    Dec 2003
    Posts
    3,366
    I dunno I take a crack at helping when I can but am no guru. I just hope I help more often than not...

Similar Threads

  1. advice on JTables and models
    By Phaelax in forum Java
    Replies: 2
    Last Post: 07-28-2005, 06:43 AM
  2. Replies: 6
    Last Post: 07-19-2005, 05:24 PM
  3. class vector<?>
    By pseudo in forum C++
    Replies: 3
    Last Post: 02-14-2005, 07:48 AM
  4. converting vector to xml
    By peter in forum Java
    Replies: 2
    Last Post: 02-28-2002, 05:07 PM
  5. Vectors and Event handling
    By Attiq in forum Java
    Replies: 1
    Last Post: 11-05-2000, 09:34 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