C++構造体ポインタと構造体配列の付与

756 ワード

ナレッジポイントのまとめ:
構造体を一括して割り当てる必要がある場合は、構造体配列を使用します.構造体ポインタは、構造体配列のヘッダアドレスを指すために使用できますが、構造体配列の付与方式で付与することはできません.後の一括付与の大きさは予知できないような気がします.詳細については、次のコードを参照してください.
#include 
using namespace std;

struct student
{
  string name;
  int score;
};



int main()
{
  //                   
  //     student *stlist = {{"a", 90}, {"b", 95}};
  student stlist[] = {{"a", 90}, {"b", 95}};
  cout << stlist[0].name << " " << stlist[0].score << endl;
  cout << stlist[1].name << " " << stlist[1].score << endl;

  //new             
  student *stlist2 = new student[2]{{"a", 90}, {"b", 95}};

  return 0;
}