dimanche 6 juillet 2014

Access elements of individual tuple from a list of tuples


Vote count:

0





#include <iostream>
#include <fstream>
#include <list>
#include <tuple>

using namespace std;

int main()
{
list<tuple<char,double,double>> XYZ_Widget_Store;

ifstream infile;
infile.open("data.text");

char x; // S, P, R
double a,b;

for(;infile >> x >> a >> b;){
XYZ_Widget_Store.push_back(make_tuple(x,a,b));
}

infile.close();

for(list<int>::iterator it = XYZ_Widget_Store.begin(); it !=
XYZ_Widget_Store.end(); ++it){
cout << *it.get<0> << endl;
}
return 0;


}


Let's say that the first item on my list contains a tuple ('a',1,1) how do I get the first element 'a' from that tuple ? usually it is just get<0>(mytuple) but being in a list makes it difficult to understand. I want to iterate through the list and get every first element from every element in the list. The element of the list is itself a tuple.



asked 7 mins ago






Aucun commentaire:

Enregistrer un commentaire