Pair de vector c++

Asked

Viewed 470 times

1

I implemented the traveling salesman and show the minimum cost of all paths. Now I want to show the path that corresponds to the lowest cost. I’m using to do this one pair<int, vector<int> > x, where as first I place the minimum cost and on the Second I place my path vector.

When I put x.make_pair(custoMinimo, push_back(caminho)), he makes the mistake:

struct std::pair<int, std::vector<int> >’ has no member named ‘make_pair’

Does anyone have any idea how to fix this?

1 answer

2

make_pair is not an instance method x, and a method that returns a pair. Therefore, Voce needs to use so:

x = make_pair(custoMinimo, push_back(caminho))
  • It worked here Lucas, thanks ! Let me just ask you something else, how would I sweep this pair of vector ? As the size is not part of pair, as we would do ?

  • And a usual pair, then x.first and a whole and x.second and a vector. So Voce can do something like for (auto &it : x.second) cout << it << endl; or something like that to print the integers in the vector.

  • 1

    @user15930 if the reply meets you can mark as "Accept" by clicking on the check mark next to the reply (in V form). More information here: How and why to accept an answer?

  • worked out, thanks Lucas !

  • so a detail, @user15930, I used a few things from the 'recent' pattern of c++, grandchild may not work on old compilers.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.