GeekBand-C++STL与泛型编程-Week1

vector

constructor

std::vector first;
std::vector second(4, 100);
std::vector third (second.begin(),second.end());
std::vector fourth (third);
int myints[] = {16,2,77,29};
std::vector fifth (myints, myints + sizeof(myints) / sizeof(int) );
std::vector sixth = fifth;
std::vector seventh = std::move(sixth);  // 移动构造

常用操作

class A {
public:
    A(int a) {}
};
std::vector v;
v.push_back(A(1));
v.emplace_back(1); // 直接原地构造,节省一次拷贝开销
v.pop_back();
v.erase(v.begin());

你可能感兴趣的:(GeekBand-C++STL与泛型编程-Week1)