Je suis en train de mettre en œuvre un arbre B en C ++, j'ai une pile qui enregistre des paires. Mon problème est, comment je mets dans cette pile parce que vous n'acceptez que 1 argument. merci p>
4 Réponses :
Utiliser std :: paire fournie par la bibliothèque standard.
Vous pouvez les créer avec la fonction make_pair . P>
#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; }
Merci. Je ne sais pas stl. C'est juste que j'en ai besoin. Merci à tout le monde.
#include <utility> // ... stack<pair<string,string> > s; s.push(make_pair("roses", "red"));
#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; }
int main() { stack <pair<int,int> > s; s.push({1,2}); cout << s.top().first << " " << s.top().second; }
Pouvez-vous clarifier votre problème? Maintenant, il semble un simple
stack.push (std :: make_pair (premier, seconde)); code> avec
pile code> être un
std :: pile> code> est tout ce dont vous avez besoin.