Im implémentation d'un arbre B en C++, j'ai une pile qui sauve des paires. mon problème est, comment je mets dans cette pile parce que push n'accepte que 1 argument. merciStack STL avec 2 paramètres
5
A
Répondre
3
#include <utility>
// ...
stack<pair<string,string> > s;
s.push(make_pair("roses", "red"));
6
Utilisez la paire std :: fournie par la bibliothèque standard.
Vous pouvez les créer avec la fonction 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;
}
+0
merci. Je ne sais pas STL. c'est juste que j'en ai besoin. Merci à tout le monde. – petercartagena
3
#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;
}
Pouvez-vous clarifier votre problème? Maintenant, il semble qu'un simple 'stack.push (std :: make_pair (premier, second));' avec 'stack' étant un' std :: stack> 'est tout ce dont vous avez besoin. –
Pieter