我正在尝试创建结构数组。下面的代码有效吗?我不断收到expected primary-expression before '{' token 错误。

int main() {
  int pause;
  struct Customer {
    int uid;
    string name;
  };

  Customer customerRecords[2];
  customerRecords[0] = {25, "Bob Jones"};
  customerRecords[1] = {26, "Jim Smith"};
  cin >> pause;
  return 0;
}

最佳答案

尝试这个:

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

10-07 23:05