If you want to reserve elements before inserting them, to make your code more efficient, you can use
vector<double> data;
data.reserve(8);
//push_back as you did
This creates an empty vector and sets the capazity to 8 elements.
You can also omit the reserve, than it will be done for you, but not in one step.
Also note that you can replace the last for loop
for (int i = 0; i < 8; i++) {
cout << data[i];
}
by a range-based for-loop, because the index is not necessary:
for (double i : data) {
cout << i;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…