By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,927 Members | 1,410 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,927 IT Pros & Developers. It's quick & easy.

How to use std::copy?

P: n/a
I have array:

double a[1024];
double b[1024];
std::vector <double> vDouble;

when I use:

std::copy(a,a+1024,vDouble.begin());

I got error.

How to use std::copy?

Also, Is the following usage correct?
std::copy(a,a+1024,b);

Jan 24 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a

kathy wrote:
I have array:

double a[1024];
double b[1024];
std::vector <double> vDouble;

when I use:

std::copy(a,a+1024,back_inserter(vDouble));

I got error.

How to use std::copy?

Also, Is the following usage correct?
std::copy(a,a+1024,b);


Jan 24 '06 #2

P: n/a
kathy wrote:
I have array:

double a[1024];
double b[1024];
std::vector <double> vDouble;

when I use:

std::copy(a,a+1024,vDouble.begin());

I got error.
Yes. Your vector is empty. You need to either resize it to 1024 elements
or copy to a 'back_inserter(vDouble)'.
How to use std::copy?

Also, Is the following usage correct?
std::copy(a,a+1024,b);


Yes.

V
Jan 24 '06 #3

P: n/a

"kathy" <yq*****@yahoo.com> wrote in message
news:11**********************@g14g2000cwa.googlegr oups.com...
I have array:

double a[1024];
double b[1024];
std::vector <double> vDouble;

when I use:

std::copy(a,a+1024,vDouble.begin());

I got error.

How to use std::copy?

Also, Is the following usage correct?
std::copy(a,a+1024,b);


Victor's answer is correct of course, but actually this isn't a great usage
of std::copy. It is probably better to declare vDouble as

std::vector<double> vDouble(a, a+1024);

If your standard library implementation is any good this should prevent
anything ugly from happening (such as initializing all 1024 elements to 0.0
and then overwriting them immediately or doing all the bookkeeping for 1024
push_back operations).
Jan 25 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.