Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C - C++ Learning > Re: copy values...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 6 Topic 4138 of 4262
Post > Topic >>

Re: copy values from

by "Jim Langston" <tazmaster@[EMAIL PROTECTED] > May 6, 2008 at 12:37 AM

Gerhard Wolf wrote:
> Hi,
>
> i have to vectors.
> std::vector<double> a;
> std::vector<double> b;
> same type, size and have synchronous value pairs. The values in "a"
> are decimal time values (linear increasing).
>
> Now i want to copy in a 3rd vector "c" all elements from a start value
> to a end value. My first idea was something like:
>
> std::vector<double> c;  // target
> for (std::vector<double>::iterator it=a.begin(); it != a.end(); it++)
>   { if (*it > startvalue && *it < endvalue) {
>     c.push_back(?);
>  }
> }
>
> do i need a 2nd iterator for vector b !? but how?
> or ist there a easier was to get the values to vector c?

It is hard to understand what, exactly, you want vector c to end up 
containing.

For example, say vector a is:
1.0, 1.5, 2.0, 2.5
and vector b is:
12.0, 12.25, 12.5, 12.75

What do you want vector c to contain?

In this case it would probably be better to use an index.

for ( std::size_t i = 0; i < a.size() && i < b.size(); ++i )
{
   // Here you can reference a[i] and b[i] or a.at(i) b.at(i)
}


-- 
Jim Langston
tazmaster@[EMAIL PROTECTED]

 




 6 Posts in Topic:
copy values from
Gerhard Wolf <quisquil  2008-05-06 08:53:38 
Re: copy values from
"Jim Langston"   2008-05-06 00:37:49 
Re: copy values from
Gerhard Wolf <quisquil  2008-05-06 09:41:37 
Re: copy values from
Francis Glassborow <fr  2008-05-06 08:40:03 
Re: copy values from
Jerry Coffin <jcoffin@  2008-05-06 23:45:58 
Re: copy values from
Gerhard Wolf <quisquil  2008-05-07 11:39:18 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Sep 6 13:31:31 CDT 2008.