cplusplus
.com
TUTORIALS
REFERENCE
ARTICLES
FORUM
C++
Tutorials
Reference
Articles
Forum
Forum
Beginners
Windows Programming
UNIX/Linux Programming
General C++ Programming
Lounge
Jobs
Forum
Beginners
Assigning arrays to other arrays
Assigning arrays to other arrays
Oct 4, 2013 at 1:41am UTC
ivan1
(34)
Hi all,
I have an array of numbers whose size is 15. Say, array[15]. At some point, in my code, I want to assign array2 to array by:
if(value1 <= value2)
{
array = array2;
}
where value1 and value2 are calculated based on array1 and array2, respectively.
Is this the proper way to do this? Do i need an index?
Thanks in advance.
Oct 4, 2013 at 1:45am UTC
LB
(13399)
You need to assign each individual index from array2 into array:
http://www.cplusplus.com/reference/algorithm/copy/
1
2
3
4
if
(value1 <= value2) { std::copy(array2, array2 + 15, array); }
Oct 4, 2013 at 2:48am UTC
ivan1
(34)
Thanks for your help first of all. When I used this command, I get the following error:
error: request for member âbeginâ in âarrayâ, which is of non-class type âint [(((long unsigned int)(((long int)numLocation) + -0x00000000000000001)) + 1)]â
How can this be fixed?
Thanks
Oct 4, 2013 at 2:55am UTC
LB
(13399)
I don't know, the syntax is correct and it compiles for me:
http://ideone.com/JfiLOQ
Can you show me your entire program?
Topic archived. No new replies allowed.