2

I have declared the following two arrays. One is a single array of 4 elements, The other is a multidimensional array of 5 rows and 4 colums (see diagram below).

array<String^> ^single_row = {"E1", "E2", "E3", "E4"};
array<String^,2>^ multi_row=gcnew array<String^,2>(5,4);

Is there built in function I can use to copy the first array let's say the third row of the second array, without manually copying each element?
Note: I've tried array->copy but experienced error C3262: invalid array indexing: 1 dimension(s) specified for 2-dimensional 'cli::array ^'

I've attached a diagrams to assist for visualisation purposes. Array diagrams

Peter H
  • 871
  • 1
  • 10
  • 33
  • possible dup of http://stackoverflow.com/questions/3902215/using-memcpy-to-copy-a-range-of-elements-from-an-array – stark Feb 26 '13 at 00:41
  • there is no memcpy for c++ clr though – TravellingGeek Feb 26 '13 at 01:27
  • maybe the way you use array->copy is incorrect. try something like Array::Copy(single_row,multi_row[3],4); specifying the row where to copy in multi_row – TravellingGeek Feb 26 '13 at 01:32
  • @stark This is not a duplicate. The link you have is of unmanaged c++ and the copy of a single arary. – Peter H Feb 26 '13 at 02:51
  • @GeraldSv I get the following errors when trying Array::Copy(single_row,multi_row[3],4); Error 1 error C3262: invalid array indexing: 1 dimension(s) specified for 2-dimensional 'cli::array ^' Error 2 error C2665: 'System::Array::Copy' : none of the 5 overloads could convert all the argument types – Peter H Feb 26 '13 at 02:52

1 Answers1

1

I didn't find any function to do this. The only thing that I've found is that you can create the first array as multidimensional too.

array<String^,2> ^single_row = {{"E1", "E2", "E3", "E4"}};
array<String^,2>^ multi_row=gcnew array<String^,2>(5,4);

Then use:

Array::Copy(single_row,0,multi_row,2*4,4);

I hope this helps.

Kindest Regards

KooKoo

KooKoo
  • 451
  • 3
  • 20