Vector-Constructors

////////////////////////////////////////
//      2018/04/15 17:15:44
//      Vector-Constructors

#include<iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main(){
    // empty vector object
    vector<int> v1;

    // creates vector with 10 empty elements
    vector<int> v2(10);

    // creates vector with 10 empty elements,and assign value 0 for each
    vector<int> v3(10, 0);

    // create vector and assigns  values from string array
    string str[] = { "Alex", "John", "Robert" };
    vector<string> v4(str + 0, str + 3);
    vector<string>::iterator slt = v4.begin();
    while (slt != v4.end()){
        cout << *(slt++) << " ";
    }
    cout << endl;

    // copy constructor 
    vector<string> v5(v4);
    for (int i = 0; i < 3; i++){
        cout << v5[i] << " ";
    }
    cout << endl;
    return 0;
}
阅读更多

扫码向博主提问

小小妖妖

非学,无以致疑;非问,无以广识
去开通我的Chat快问
版权声明:我是一只快乐的小妖精 https://blog.csdn.net/qwq1503/article/details/79951744
个人分类: STL
所属专栏: C++STL样列
上一篇C++:多维数组的动态分配(new)和释放(delete)
下一篇Vector-assign
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭
关闭