Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ C++;如何打印此地图std::map<;int,pair<;向量<;配对<;int,int>>;,int>&燃气轮机;_C++ - Fatal编程技术网

C++ C++;如何打印此地图std::map<;int,pair<;向量<;配对<;int,int>>;,int>&燃气轮机;

C++ C++;如何打印此地图std::map<;int,pair<;向量<;配对<;int,int>>;,int>&燃气轮机;,c++,C++,我想在地图中打印成对,如: std::map<int, pair<vector<pair<int, int>>, int>> Mymap; 我想打印这样的双: { 1, 3 }, { 1, 5 } { 2, 3 }, { 3, 7 }, { 1, 3 } 因此,好的第一步是实际编写示例数据,使其与您请求的类型匹配 也许是这样的: Mymap[0] = {{{1, 3}, {1, 5}}, 4}; Mymap[1] = {{{2, 3}, {

我想在地图中打印成对,如:

std::map<int, pair<vector<pair<int, int>>, int>> Mymap;
我想打印这样的双:

{ 1, 3 }, { 1, 5 } 
{ 2, 3 }, { 3, 7 }, { 1, 3 } 

因此,好的第一步是实际编写示例数据,使其与您请求的类型匹配

也许是这样的:

Mymap[0] = {{{1, 3}, {1, 5}}, 4};
Mymap[1] = {{{2, 3}, {3, 7}, {1, 3}}, 8};
然后,我们可以很容易地迭代这个

#include <map>
#include <vector>
#include <iostream>

int main() {
    std::map<int, std::pair<std::vector<std::pair<int, int>>, int>> Mymap;

    Mymap[0] = {{{1, 3}, {1, 5}}, 4};
    Mymap[1] = {{{2, 3}, {3, 7}, {1, 3}}, 8};

    for (const auto & pair : Mymap) {
        for (const auto & pair : pair.second.first) {
            std::cout << "{" << pair.first << ", " << pair.second << "}, ";
        }
        std::cout << "\n";
    }
}

我看不出你的问题有什么道理,你到底想做什么

无论如何,这段代码应该能够做到:

    std::map<int, pair<vector<pair<int, int>>, int>> Mymap;
    Mymap[0] = {{{1, 3}, {1, 5}}, 4};
    Mymap[1] = {{{2, 3}, {3, 7}, {1, 3}}, 8};
    map<int, pair<vector<pair<int, int>>, int>>::iterator it;
    for (it=Mymap.begin(); it!=Mymap.end(); it++){
        pair<vector<pair<int, int>>, int> myPair=it->second;
        vector<pair<int, int>> myVec=myPair.first;
        for (int i=0; i<myVec.size(); i++){
            cout<< "{ " << myVec[i].first << ","<<myVec[i].second<< " }, ";

        }
        cout<<endl;
    }
std::map Mymap;
Mymap[0]={{{{1,3},{1,5},4};
Mymap[1]={{{{2,3},{3,7},{1,3},8};
对它进行迭代器;
for(it=Mymap.begin();it!=Mymap.end();it++){
pair myPair=it->second;
向量myVec=myPair.first;

对于(int i=0;我很好!你有问题吗?你能从int->int的地图上打印值吗?或者你在地图上行走以及拉出配对的
第一部分吗?这个问题似乎脱离了主题,因为它是一篇博客文章,而不是一个问题。
{1, 3}, {1, 5}, 
{2, 3}, {3, 7}, {1, 3}, 
    std::map<int, pair<vector<pair<int, int>>, int>> Mymap;
    Mymap[0] = {{{1, 3}, {1, 5}}, 4};
    Mymap[1] = {{{2, 3}, {3, 7}, {1, 3}}, 8};
    map<int, pair<vector<pair<int, int>>, int>>::iterator it;
    for (it=Mymap.begin(); it!=Mymap.end(); it++){
        pair<vector<pair<int, int>>, int> myPair=it->second;
        vector<pair<int, int>> myVec=myPair.first;
        for (int i=0; i<myVec.size(); i++){
            cout<< "{ " << myVec[i].first << ","<<myVec[i].second<< " }, ";

        }
        cout<<endl;
    }