|
Boost : |
From: Jonathan Wakely (cow_at_[hidden])
Date: 2005-05-05 05:30:08
On Thu, May 05, 2005 at 06:10:32PM +0800, zlf wrote:
> Hi all,
> What is the easiest way to assign mulitply value for a defined number
> array?
>
> Assigning mulitply elements' value when defining like this will be OK.
> int test [ 2 ] = { 1 , 2 };
>
> If I want to assign value for the number array [test] after defining it.
> I only know I can achieve this by the following step.
>
> int test [ 2 ];
> test [ 0 ] = 1;
> test [ 1 ] = 2;
>
> [int test [ 2 ]; test = { 1 , 2 };] seems easy and reasonable. But
> executing it will get a compile error. What is the easiest way to assign
> mulitply value for a defined number array? Thx
Using nothing non-std you can initialise another array and copy from it:
int test [ 2 ];
// ...
int tmp[2] = { 1, 2 };
std::copy(tmp, tmp+2, test);
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk