Im implementing a B-tree in C++,I have a stack which saves pairs . my problem is, how i put in this stack because push only accept 1 argument. thanks
+6
A:
Use std::pair provided by the standard library.
You can create them with the function make_pair.
#include <iostream>
#include <stack>
#include <string>
using namespace std;
int main(int argc, char **argv)
{
int myInt = 1;
string myString("stringVal");
stack<pair<string, int> > myStack;
myStack.push(make_pair(myString, myInt));
return 1;
}
RC
2010-05-27 16:43:00
thanks. I don´t kwon STL. it´s just i need it. thanks to everyone.
petercartagena
2010-05-27 17:42:09
+2
A:
#include <utility>
// ...
stack<pair<string,string> > s;
s.push(make_pair("roses", "red"));
wilhelmtell
2010-05-27 16:44:56
A:
#include <stack>
#include <utility>
#include <iostream>
using namespace std;
int main() {
stack <pair<int,int> > s;
s.push( make_pair( 1, 2 ) );
pair <int, int> p = s.top();
cout << p.first << " " << p.second << endl;
}
anon
2010-05-27 16:48:30