Help | Site Map
Connecting Tech Pros Worldwide
 
 
LinkBack Thread Tools
  #1  
Old January 24th, 2006, 10:45 PM
kathy
Guest
 
Posts: n/a
Default How to use std::copy?

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);

  #2  
Old January 24th, 2006, 10:55 PM
roberts.noah@gmail.com
Guest
 
Posts: n/a
Default Re: How to use std::copy?


kathy wrote:[color=blue]
> 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);[/color]

  #3  
Old January 24th, 2006, 11:05 PM
Victor Bazarov
Guest
 
Posts: n/a
Default Re: How to use std::copy?

kathy wrote:[color=blue]
> 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.[/color]

Yes. Your vector is empty. You need to either resize it to 1024 elements
or copy to a 'back_inserter(vDouble)'.
[color=blue]
> How to use std::copy?
>
> Also, Is the following usage correct?
> std::copy(a,a+1024,b);[/color]

Yes.

V
  #4  
Old January 25th, 2006, 02:25 AM
Cy Edmunds
Guest
 
Posts: n/a
Default Re: How to use std::copy?


"kathy" <yqin_99@yahoo.com> wrote in message
news:1138142243.335413.284680@g14g2000cwa.googlegr oups.com...[color=blue]
>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);
>[/color]

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).


 

Bookmarks

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over network members.
Post your question now . . .
It's fast and it's free

Popular Articles