排列とは違って、データ型の異なる値が複数まとめて扱える。
#include <iostream> #include <string> using namespace std; // 構造体は普通はヘッダーファイルで宣言するとの由。 struct qb { string Name; int Att; int Comp; int Yds; int Td; int Int; }; int main(){ qb Seahawks = {"Wilson, Russell",31,21,225,2,0}; // qb型のデータを初期化して、 cout << Seahawks.Name << endl; // 各要素を読み出してみる。ドット記法で読み出せる。 cout << Seahawks.Att << endl; cout << Seahawks.Comp << endl; cout << Seahawks.Yds << endl; cout << Seahawks.Td << endl; cout << Seahawks.Int << endl; Seahawks.Int = 999999; // 要素ごとに書き込むこともできる。ドット記法で書き込める。 cout << Seahawks.Int << endl; system("pause"); return 0; }