user2793559
user2793559

Reputation: 103

vector initialization in vs2010

#include <iostream>
#include <vector>
#include <stdio.h>
using namespace std;
class M {
    vector<string> s;
    public:
    M(){
        s = {"abc", "abc", "abc", "abc", "abc"};
    }
};

int main(){
    return 0;
}

The code can be compiled in c9, but in vs2010, it can't be compiled successfully.why?

Upvotes: 1

Views: 1731

Answers (2)

Subhajit
Subhajit

Reputation: 320

You may follow this,

static const string arrStr[] = {"abc", "abc", "abc", "abc", "abc"};
vector<string> s(arrStr, arrStr + sizeof(arrStr)/sizeof(arrStr[0]));

Upvotes: 1

Vlad from Moscow
Vlad from Moscow

Reputation: 310980

MS VC++ 2010 does not support std::initializer_list as a parameter for member functions of standard containers.

Upvotes: 3

Related Questions