Structure of assigning values to an array member in C++
Hello friend,
My code is as follows(In bold-part question):
#include "stdafx.h"
#include <iostream>
using namespace std;;
#define MAX_ARR_SIZE 10
typedef int ElementType;
typedef struct
{
ElementType arr[MAX_ARR_SIZE];
int length;
}MyStr;
void outputE(MyStr *ms){
int i;
for (i = 0; i < ms->length; i++) cout << ms->arr[i] << ",";
cout << ms->arr[i] << endl;
}
int _tmain(int argc, _TCHAR* argv[]){
MyStr ms;
ms.length = MAX_ARR_SIZE;
// try a one-time assignment. but a compiler error has occurred(In addition to each assignment, but are there other ways?).
ms.arr[MAX_ARR_SIZE] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
outputE(&ms);
system("pause");
return 0;
}
Thanks.