I am trying to insert a vector into a larger vector at various
positions. This, however, will not compile.
vector<double>::iterator pos;
vector<double> tmp;
vector<double> m_parameters;
vector<double> param_start; //vector of start positions in
m_parameters
for (int i=0; i<7; i++)
{
m_parameters.insert(pos[param_start[i]],tmp.begin(),tmp.end());
}
And, then assigning the smaller vectors from the larger one, also
doesn't work.
for (int i=0; i<7; i++)
{
tmp.assign(m_parameters.begin() +
param_start[i],m_parameters.begin()+param_start[i+1]));
}
Am I missing something here? Vector iterators seem to be problematic.
Thanks a bunch! 2 1310
agenevera wrote: I am trying to insert a vector into a larger vector at various positions. This, however, will not compile. vector<double>::iterator pos; vector<double> tmp; vector<double> m_parameters; vector<double> param_start; //vector of start positions in m_parameters
If it's a vector of positions, shouldn't it be
vector<size_t>
or
vector<int>
at least?
for (int i=0; i<7; i++) { m_parameters.insert(pos[param_start[i]],tmp.begin(),tmp.end()); } And, then assigning the smaller vectors from the larger one, also doesn't work. for (int i=0; i<7; i++) { tmp.assign(m_parameters.begin() + param_start[i],m_parameters.begin()+param_start[i+1])); } Am I missing something here? Vector iterators seem to be problematic.
I think you've completely missed the point of the iterators. What book on
C++ are you reading that doesn't explain iterators?
V
--
Please remove capital As from my address when replying by mail
In article <11**********************@g47g2000cwa.googlegroups .com>,
"agenevera" <ga****@rice.edu> wrote: I am trying to insert a vector into a larger vector at various positions. This, however, will not compile.
vector<double>::iterator pos; vector<double> tmp; vector<double> m_parameters; vector<double> param_start; //vector of start positions in m_parameters for (int i=0; i<7; i++) { m_parameters.insert(pos[param_start[i]],tmp.begin(),tmp.end());
pos[param_start[i]] is not an iterator. Try this instead:
pos = m_parameters.begin() + param_start[i];
m_parameters.insert( pos, tmp.begin(), tmp.end() );
You did it right below...
} And, then assigning the smaller vectors from the larger one, also doesn't work. for (int i=0; i<7; i++) { tmp.assign(m_parameters.begin() + param_start[i],m_parameters.begin()+param_start[i+1]));
The above doesn't work for me because I have an old compiler, you may
have the same problem? I had to do:
pos = m_parameters.begin();
tmp.assign( pos + param_start[i], pos + param_start[i + 1] );
}
Am I missing something here? Vector iterators seem to be problematic. Thanks a bunch!
--
Magic depends on tradition and belief. It does not welcome observation,
nor does it profit by experiment. On the other hand, science is based
on experience; it is open to correction by observation and experiment. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Dave |
last post by:
I'm crossposting this to both comp.lang.c++ and gnu.gcc because I'm not
sure if this is correct behavior or not, and I'm using the gcc STL and
compiler.
When calling vector<int>::push_back(0),...
|
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...
|
by: Adam Hartshorne |
last post by:
Hi All,
I have the following setup. Two 'std::vector's which i iterate through in a
for (iterate through vector1 of types X) {
for (iterate through vector2 of types Y) {
f(x)
}
|
by: laniik |
last post by:
Hi. I have a problem using STL's built in sort that seems impossible
to get around.
if i have:
--------------------------------
struct object
{
int val;
}
|
by: codefixer |
last post by:
Hello,
I am trying to understand if ITERATORS are tied to CONTAINERS.
I know the difference between 5 different or 6(Trivial, on SGI).
But what I fail to understand is how can I declare all 5...
|
by: zaineb |
last post by:
Hi,
This is a follow-up of sort of this thread:...
|
by: ma740988 |
last post by:
typedef std::vector < std::complex < double > > complex_vec_type;
// option1
int main()
{
complex_vec_type cc ( 24000 );
complex_vec_type dd ( &cc, &cc );
}
versus
|
by: fungus |
last post by:
I'm moving some code from VC++ 6 to VC++ 2005 and
I've run into a nasty problem because iterators
are no longer pointers.
In the program I'm moving, there's a std::vector
of items hidden inside...
|
by: desktop |
last post by:
1)
I have this code:
std::list<intmylist;
mylist.push_back(1);
mylist.push_back(2);
mylist.push_back(3);
mylist.push_back(4);
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |