c++ vector initialization

前端 未结 5 847
抹茶落季
抹茶落季 2020-12-20 15:47

I have been using the following vector initialization with values in Code::Blocks and MingW compiler:

vector v0 {1,2,3,4};

A

5条回答
  •  爱一瞬间的悲伤
    2020-12-20 16:17

    You can do nearly that in VS2013

    vector v0{ { 1, 2, 3, 4 } };
    

    Full example

    #include 
    #include 
    int main()
    {    
        using namespace std;
        vector v0{ { 1, 2, 3, 4 } };
        for (auto& v : v0){
            cout << " " << v;
        }
        cout << endl;
        return 0;
    }
    

提交回复
热议问题