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

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

Jan 24 '06 #1
3 29108

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

"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Thomas J. Clancy | last post by:
I was wondering if anyone knew of a way to use std::copy() and istream_iterator<>/ostream_iterator<> write a file copy function that is quick and efficient. Doing this messes up the file because...
30
by: franky.backeljauw | last post by:
Hello, I am wondering which of these two methods is the fastest: std::copy, which is included in the standard library, or a manually written pointer copy? Do any of you have any experience with...
4
by: Simon Elliott | last post by:
Is there an equivalent of std::copy which works on STL containers for overlapping ranges? -- Simon Elliott http://www.ctsn.co.uk
1
by: Siegfried Heintze | last post by:
What is the minimum I must type to create a custom iterator that will allow me display my iterator on std::cout using std::copy? Thanks, Siegfried
1
by: Siegfried Heintze | last post by:
Should the following work? It does on some compilers. How can I get it to work on g++ 3.2? On g++ 3.2 it keeps telling me that there is no such function operator << for ostream and...
6
by: Chris Johnson | last post by:
Greetings all. I am really stuck on this one as I can't seem to grok if I am abusing the C++ language or if I am simply using components of the C++ Standard Library incorrectly. Here is the code:...
5
by: Pradeep | last post by:
Hi All, I am facing some problem using istream_iterator for reading the contents of a file and copying it in a vector of strings.However the same thing works for a vector of integers. The...
3
by: none | last post by:
Hi, Consider the following piece of code: int t={1,2,3,4,5,6}; vector<intv; std::copy (t, t+sizeof(t)/sizeof(t), std::back_inserter (v)); Could someone explain me why we can pass "t" as an...
9
by: arnuld | last post by:
Earlier, I have posted a program like this, a month ago IIRC. I have created it again, without looking at the old program. Can I have your opinions on this: 1) I wanted my program to be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.