473,394 Members | 2,048 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,394 software developers and data experts.

problem with vector iterators

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!

Feb 14 '06 #1
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
Feb 14 '06 #2
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.
Feb 15 '06 #3

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

Similar topics

2
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),...
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...
6
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) }
8
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; }
3
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...
13
by: zaineb | last post by:
Hi, This is a follow-up of sort of this thread:...
2
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
15
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...
18
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);
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: 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
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
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?
0
marktang
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,...
0
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...
0
jinu1996
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...
0
tracyyun
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...

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.