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

Simple pointer question (:)

P: n/a
J
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's values
into 'array2'?


TIA,
-- JA
Jul 22 '05 #1
Share this Question
Share on Google+
5 Replies


P: n/a

"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's values into 'array2'?


TIA,
-- JA


memcpy(array2, array, 50 * sizeof(double));
Jul 22 '05 #2

P: n/a
J
Thanks my friend, totally forgot memcpy. (Haven't programmed in awhile!!)
- JA
"Thomas Wintschel" <th******@telus.net> wrote in news:PHTyb.91295
$oN2.40286@edtnps84:

"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's

values
into 'array2'?


TIA,
-- JA


memcpy(array2, array, 50 * sizeof(double));


Jul 22 '05 #3

P: n/a

"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's values into 'array2'?


std::copy(array, array + 50, array2);

This assumes that 'array' and 'array2' each have at least
50 elements, and that all elements of 'array' have valid
values.

'std::copy()' is declared by <algorithm>.

-Mike
Jul 22 '05 #4

P: n/a
Thomas Wintschel wrote:
"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's
values
into 'array2'?



memcpy(array2, array, 50 * sizeof(double));

Hmm...whats memcpy doing in a c++ forum :-)
Jul 22 '05 #5

P: n/a

"Roy Varghese" <rv*******@usersDOTsf.net> wrote in message
news:RoYyb.391727$Tr4.1147654@attbi_s03...
Thomas Wintschel wrote:
"J" <ni********@gl.gl> wrote in message
news:Xn**********************@130.215.36.210...
Hi,

I have an array:

double *array = new double[50];
Well, I have 2 actually.
double *array2 = new double[50];
Say 'array' is poulated with 'doubles'. How do I copy all of array's


values
into 'array2'?



memcpy(array2, array, 50 * sizeof(double));

Hmm...whats memcpy doing in a c++ forum :-)


memcpy() is a standard C++ library function.

-Mike
Jul 22 '05 #6

This discussion thread is closed

Replies have been disabled for this discussion.