consider this :
now how do I assign and/or access each vector and/or pair in here?Code:typedef pair<char,char> twin; vector<twin> here;
I tried here.first and twin.first and both didnt worked...
Luigi
consider this :
now how do I assign and/or access each vector and/or pair in here?Code:typedef pair<char,char> twin; vector<twin> here;
I tried here.first and twin.first and both didnt worked...
Luigi
youll have to make sure there are values in the vector first. But once there are, you can index just like a normal array
twin t;
vector<twin> v;
v.push_back(t);
v[0]. // whatever methods pair contains
C Code. C Code Run. Run Code Run... Please!
"Love is like a blackhole, you fall into it... then you get ripped apart"
You use "first" and "second" to access the parts of the pair. Here is a simple example.
Code:#include <utility> #include <iostream> using namespace std; // Less typing later.. typedef struct pair< float, int > myPair; int main( int argc, char *argv[] ) { // Use helpful function to assign values to pair myPair pair1 = make_pair( 25.5f, 5 ); // Output values cout << pair1.first << " " << pair1.second << endl; // Assign new values using first and second pair1.first = 101.2f; pair1.second = 55; // Output new values cout << pair1.first << " " << pair1.second << endl; return 0; }
Well the first reply explains how to use vectors the second explains pairs
Just do as both people said.
Code:my_pair_vect[0].first = whatever;
So shouldn't the title be vector of pairs?