在C++中,數組賦值有以下幾種方式:
int arr[5];
for(int i = 0; i < 5; i++) {
arr[i] = i + 1;
}
int arr1[5] = {1, 2, 3, 4, 5};
int arr2[5];
memcpy(arr2, arr1, sizeof(arr1));
int arr1[5] = {1, 2, 3, 4, 5};
int arr2[5];
std::copy(std::begin(arr1), std::end(arr1), std::begin(arr2));
int arr1[5] = {1, 2, 3, 4, 5};
int arr2[5];
for(int i = 0; i < 5; i++) {
arr2[i] = arr1[i];
}