C++: How can I push to elements of an array into a list of arrays? -


i 2 variables a , b , want add them directly list of arrays. how can avoid define array, pushed list afterwards?

i searching construction similar line beginning //.

minimal example:

#include <list> #include <boost/array.hpp>  using namespace std;  int main() {     cout << endl;      /* given values */     int = 1;     int b = 2;      /* arraylist contains arrays of integers. */     list<boost::array<int, 2> > arraylist;      /* item add values */     boost::array<int, 2> item;      item[0] = a;     item[1] = b;     arraylist.push_back(item);  //  arraylist.push_back({{a, b}});      cout << arraylist.front()[0] << ", " << arraylist.front()[1] << endl;      return 0;  } 

my g++ version following: gcc-version 4.6.3 (ubuntu/linaro 4.6.3-1ubuntu5).

compiling (within eclipse) throws warning listed error: warnung: erweiterte initialisierungsliste nur mit -std=c++0x oder -std=gnu++0x verfügbar [standardmäßig aktiviert] main.cpp /testarraylistandfind line 24 c/c++ problem means: extended initilization list ... or ... available.

you use boost::assign::list_of if don't have c++11 support:

arraylist.push_back(boost::assign::list_of(1)(2)); 

Comments

Popular posts from this blog

jquery - Invalid Assignment Left-Hand Side -

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -