tags:

views:

79

answers:

3

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
thanks. I don´t kwon STL. it´s just i need it. thanks to everyone.
petercartagena
+2  A: 
#include <utility>

// ...
stack<pair<string,string> > s;
s.push(make_pair("roses", "red"));
wilhelmtell
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