c++ - How do I create a multidimensional vector/array of different types? -


i know create multidimensional vector you'd need write this

std::vector< std::vector <int> > name; std::vector<int> firstvector; firstvector.push_back(10); numbers.push_back(thisvector); std::cout << numbers[0][0] 

output 10.

however trying create table of 3 different types. first column string, second ints, , third doubles.

output of table this

one     200    5.1% 3    10    1.4% 9   5000   10.8% 

i'm not sure followed explanation, sounds want vector of structures:

struct whatever {      std::string first; // first column string     int second;        // ...the second ints     double third;      // ...and third doubles. };  std::vector<whatever> data; 

as far output goes, you'd define operator<< handle that:

std::ostream &operator<<(std::ostream &os, whatever const &w) {       os << std::setw(10) << w.first          << std::setw(5) << w.second          << std::setw(9) << w.third;      return os; } 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -