zoukankan      html  css  js  c++  java
  • 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;
    }
  • 相关阅读:
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    PatentTips
    How to build and run ARM Linux on QEMU from scratch
    How to debug Android Native Application with eclipse
  • 原文地址:https://www.cnblogs.com/laohaozi/p/12538064.html
Copyright © 2011-2022 走看看