Ich habe alles versucht, was ich könnte, aber dieser Code gibt mir Fehler. Beide Syntax funktionieren nicht. Ich habe den Operator [] kommentiert, aber bitte geben Sie auch eine Lösung dafür an.Vektor von Tuples in C++
#include <bits/stdc++.h>
using namespace std;
int main() {
typedef vector< tuple<int, int, int> > my_tuple;
my_tuple tl;
tl.push_back(tuple<int, int, int>(21,20,19));
for (my_tuple::const_iterator i = tl.begin(); i != tl.end(); ++i) {
//cout << get<0>(tl[i]);
//cout << get<0>(tl[i]);
//cout << get<0>(tl[i]);
cout << get<0>(tl.at(i));
cout << get<1>(tl.at(i));
cout << get<2>(tl.at(i));
}
return 0;
}
beim Drucken Tupel in for Schleife bekomme ich Fehler.
error: no matching function for call to 'std::vector<std::tuple<int, int, int> >::at(std::vector<std::tuple<int, int, int> >::const_iterator&)'
und für Operator []
error: no match for 'operator[]' (operand types are 'my_tuple {aka std::vector<std::tuple<int, int, int> >}' and 'std::vector<std::tuple<int, int, int> >::const_iterator {aka __gnu_cxx::__normal_iterator<const std::tuple<int, int, int>*, std::vector<std::tuple<int, int, int> > >}')
Nicht '# include'. Sie sollten '' und '' und '' einschließen. Diese Bits sind interne Details, die Sie nicht verwenden sollten. –
Mögliches Duplikat von [Wie navigiere ich mit Iteratoren durch einen Vektor? (C++)] (http://stackoverflow.com/questions/2395275/how-to-navigate-through-avector-using-iterators-c) – krzaq