creating an array of structs in c++

后端 未结 4 1333
谎友^
谎友^ 2021-01-31 18:21

I\'m trying to create an array of structs. Is the code below valid? I keep getting an expected primary-expression before \'{\' token error.

int main         


        
4条回答
  •  无人共我
    2021-01-31 18:35

    Some compilers support compound literals as an extention, allowing this construct:

    Customer customerRecords[2];
    customerRecords[0] = (Customer){25, "Bob Jones"};
    customerRecords[1] = (Customer){26, "Jim Smith"};
    

    But it's rather unportable.

提交回复
热议问题