Initilizing a vector of strings where I already know all the values to populate it with C++ -
this question has answer here:
i have spent on hour researching before came guys help. using visual studio 2012 , installed update 2.
i have constructor
lexer::lexer(istream &source1, ostream& listing1) :source(source1), listing(listing1) { vector<string> tempvec = { "and", "begin", "boolean", "break", "call", "end", "else", "false", "halt", "if", "input", "integer", "is", "loop", "not", "null", "newline", "or", "output", "procedure" "return", "then", "true", "var" }; tokentostringvector = tempvec; (int k= 0; k < tokentostringvector.size(); k++) { string key = tokentostringvector[k]; lexemetotokenmap[key] = token(k); // function-style type cast } } my professor wrote header, , wrote code. getting error cannot figure out:
1>c:\users\sam\dropbox\compiler project\lexical analyzer\lexer.cpp(8): error c2552: 'tempvec' : non-aggregates cannot initialized initializer list 1> 'std::vector<_ty>' : types base not aggregate 1> 1> [ 1> _ty=std::string 1> ] i don't understand why not let me initialize this. make array, , loop add vector, using vector populate map, there must more logical way this.
thanks so! guys helpful!
please note: if answer not simple formatting error, please don't correct code, point me in right direction. graded assignment , honest student , want learn myself.
ok, replies , re-reading post posted.
- visual studio not support this, though valid in c++ 2011
thanks guys, guess need make array.
my professor told me similar , uses linux gcc compiler support this.
edit: ok, microsoft has alpha version supports this. guess i'll make array , transfer it.
thanks help!!!!
vc++ not support initializer list.
not know whether is supported in update 2, standard library not support if feature in.
edit: update 2 not support initializer list either.
Comments
Post a Comment