What is the easiest way to assign mulitply value for a defined number array?

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 zlf

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

Hi, That is a good idea.Thank you zlf "Jonathan Wakely" <cow@compsoc.man.ac.uk> ??????:20050505103008.GA31189@compsoc.man.ac.uk...
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);
_______________________________________________ Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
participants (2)
-
Jonathan Wakely
-
zlf