473,385 Members | 1,400 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

vector insert from a set

vector <int> vecThe;
set <int> setThe;

vecThe.insert (setThe.begin (), setThe.end ());

This gives an error about iterators not of the right type. Is there a
way around this or do I have to set up a for loop and do
vecThe.push_back ()?

However I can do this:

setThe.insert (vecThe.begin (), vecThe.end ());
Jul 19 '05 #1
2 5577
"Steven C" <st********@hotmail.com> wrote in message
news:76**************************@posting.google.c om...
vector <int> vecThe;
set <int> setThe;

vecThe.insert (setThe.begin (), setThe.end ());

This gives an error about iterators not of the right type. Is there a
way around this or do I have to set up a for loop and do
vecThe.push_back ()?
The vector::insert member function overload that you want
to call actually takes 3 parameters -- the first one being
the position in the vector where the insertion needs to occur:

vecThe.insert(vecThe.end(), setThe.begin(), setThe.end () );

The alternative is to use the 'assign' function, if you want
to discard any previous contents of the vector:
vecThe.assign( setThe.begin (), setThe.end ());
However I can do this:

setThe.insert (vecThe.begin (), vecThe.end ());


Yes, set is different since the insertion location
cannot be specified (value ordering is automatically
enforced).
Cheers,
Ivan
--
http://ivan.vecerina.com


Jul 19 '05 #2
Steven C escribió:
vector <int> vecThe;
set <int> setThe;

vecThe.insert (setThe.begin (), setThe.end ());


You must specify where to insert. For example:

vecThe.insert (vecThe.begin (), setThe.begin (), setThe.end ());

Regards.
Jul 19 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Alan Benn | last post by:
(VC6) When I use the STL <vector> template as follows: #include <vector> .... vector<CString> m_nameList; // Names of the chips I get these compiler warnings : C:\Program...
11
by: Richard Thompson | last post by:
I've got a memory overwrite problem, and it looks as if a vector has been moved, even though I haven't inserted or deleted any elements in it. Is this possible? In other words, are there any...
10
by: Bob | last post by:
Here's what I have: void miniVector<T>::insertOrder(miniVector<T>& v,const T& item) { int i, j; T target; vSize += 1; T newVector; newVector=new T;
3
by: eriwik | last post by:
I use the following structure to store filenames for one or more "sets" grouped together by a number: map<int, map<string> > fileSets; As arguments to the constructor I send a...
3
by: jackstah | last post by:
I've read before that subclassing off of std::vector is a bad idea because it's a concrete class. I understand, but there shouldnt be any issues with this. I just wanted to do a simple example in...
6
by: Eric Lilja | last post by:
Consider the following code: #include <iostream> #include <string> #include <vector> using namespace std; int main() {
82
by: Peter Olcott | last post by:
I need std::vector like capability for several custom classes. I already discussed this extensively in the thread named ArrayList without Boxing and Unboxing. The solution was to simply create...
12
by: desktop | last post by:
Why does insert only work when specifying an iterator plus the object to be inserted: std::vector<intt; std::vector<int>::iterator it; it = t.begin(); t.insert(it,33); If I use push_back...
13
by: jubelbrus | last post by:
Hi I'm trying to do the following. #include <vector> #include <boost/thread/mutex.hpp> #include <boost/shared_ptr.hpp> #include <boost/tuple/tuple.hpp> class {
6
by: Mr. K.V.B.L. | last post by:
I want to start a map with keys but an empty vector<string>. Not sure what the syntax is here. Something like: map<string, vector<string MapVector; MapVector.insert(make_pair("string1",...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.