#include <iostream>
#include <string>
#include <vector>
using namespace std;
using std::vector;
int main()
{
cout << "方法一:" << endl;
vector<int> ivec1(10, 42);
for (auto &c : ivec1)
cout << c << " ";
cout << endl;
cout << "方法二:" << endl;
vector<int> ivec2{42,42,42,42,42,42,42,42,42,42};
for (auto &c : ivec2)
cout << c << " ";
cout << endl;
cout << "方法三:" << endl;
vector<int> ivec3;
for (int i = 0; i != 10; ++i)
ivec3.push_back(42);
for (auto &c : ivec3)
cout << c << " ";
cout << endl;
system("pause");
return 0;
}
c++primer(第五版)3.19
最新推荐文章于 2023-12-25 23:25:03 发布