### 構造体(struct)の中にVectorを入れようとすると
#include <iostream>
using namespace std;
struct PERSON {
int age;
float weight;
vector<int> id;
} family_member;
int main() {
PERSON brother;
brother.age = 20;
brother.weight = 60.5;
brother.id = {7, 4, 0, 8};
cout << brother.id[0] << endl;
}
$ g++ -o test test.cpp && ./test
test.cpp:7:5: error: ‘vector’ does not name a type
7 | vector
| ^~~~~~
test.cpp: In function ‘int main()’:
書き方が間違っていたみたい。以下のように書くと、、、
#include <iostream>
#include <vector>
using namespace std;
struct PERSON {
int age;
float weight;
std::vector<int> id;
} family_member;
int main() {
PERSON brother;
brother.age = 20;
brother.weight = 60.5;
brother.id = {7, 4, 0, 8};
cout << brother.id[0] << endl;
}
$ g++ -o test test.cpp && ./test
7
うん、出来ますね♪ これをRustで書いていきたい。