zoukankan      html  css  js  c++  java
  • vector

    返回一个空的vector
    return {};
    # include <iostream>
    # include <vector>
    using namespace std;

    int main()
    {
    // vector < type > c1(c2);复制一个vector。
    // vector < type > c(n);创建一个vector, 含有n个数据,数据均以缺省构造产生, 即全0。
    // vector < type > c(n, elem);创建一个vector, 含有n个elem的拷贝数据。
    vector < int > v;
    vector < int >:: iterator it;
    // 用i遍历
    for (int i = 0; i < 10; i++)
    {
    // 在数组最后插入元素
    v.push_back(i);
    }
    // 删除数组最后的元素
    // v.pop_back();
    // 增
    // v.insert(v.begin() + 2, 100);
    // 删(可以是一个区间)
    // v.erase(v.begin() + 2);
    // 改(可以用指针或者下标)
    // * (v.begin()+2) = 11;
    // v.at(3) = 11;
    // 查
    cout << * (v.end()-1) << endl;
    // 用迭代器遍历
    for (it = v.begin(); it < v.end(); it++)
    {
    cout << it << ": " << * it << endl;
    }
    // 清空数组
    v.clear();
    // 是否为空
    if (v.empty())
    {
    cout << "empty" << endl;
    }
    // 数组大小
    cout << v.size() << endl;
    return 0;
    }
  • 相关阅读:
    dup和dup2
    cassandra nodetools
    python 之mechanize
    IDEA使用GsonFormat
    游标应用
    SQL 2005 with(nolock)详解
    SET NOCOUNT ON
    异常处理机制(Begin try Begin Catch)
    FILLFACTOR 作用 sql
    触发器语法
  • 原文地址:https://www.cnblogs.com/liujianing/p/13458606.html
Copyright © 2011-2022 走看看