Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.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++ 如何打印成对多集的元素 multisetml; 对p; p、 第一个=3; p、 第二,第一个=5; p、 第二,第二=2; ml.insert(p);_C++_C++11_Stl_Multiset - Fatal编程技术网

C++ 如何打印成对多集的元素 multisetml; 对p; p、 第一个=3; p、 第二,第一个=5; p、 第二,第二=2; ml.insert(p);

C++ 如何打印成对多集的元素 multisetml; 对p; p、 第一个=3; p、 第二,第一个=5; p、 第二,第二=2; ml.insert(p);,c++,c++11,stl,multiset,C++,C++11,Stl,Multiset,这就是我如何插入我的多对集合的方法 但我不知道如何打印出我的多集对中的所有元素 我试过了,但不起作用 multiset< pair<int,pair<int,int>> >ml; pair<int,pair<int,int>> p; p.first=3; p.second.first=5; p.second.second=2; ml.insert(p); multiset::对其进行迭代器; it=ml.begin(); p=*it;

这就是我如何插入我的多对集合的方法 但我不知道如何打印出我的多集对中的所有元素 我试过了,但不起作用

multiset< pair<int,pair<int,int>> >ml;
pair<int,pair<int,int>> p;
p.first=3;
p.second.first=5;
p.second.second=2;
ml.insert(p);
multiset::对其进行迭代器;
it=ml.begin();
p=*it;

cout只需在集合中迭代即可(这里基于C++11的范围很好):

for(自动x:ml)
{

cout只需在集合中迭代即可(这里基于C++11的范围很好):

for(自动x:ml)
{

有两种方法,它们几乎相同,但第二种方法要短得多

第一种方法:

for (auto x : ml)
{
    cout << "First: " << x.first <<" " << " Second first: " << x.second.first << " Second.second: " << x.second.second << endl;
}

有两种方法。它们几乎相同,但第二种方法要短得多

第一种方法:

for (auto x : ml)
{
    cout << "First: " << x.first <<" " << " Second first: " << x.second.first << " Second.second: " << x.second.second << endl;
}

你尝试过什么?你的尝试是如何成功的,还是没有成功?请学习如何创建。你尝试过什么?你的尝试是如何成功的,还是没有成功的?请学习如何创建。
for (multiset< pair<int, pair<int,int> > >::iterator it = ml.begin(); it!=ml.end(); it++) {
    cout<<"First: "<<it->first<<", Second: "<<it->second.first<<", Third: "<<it->second.second<<endl;
}
for (auto it:ml) {
    cout<<"First: "<<it.first<<", Second: "<<it.second.first<<", Third: "<<it.second.second<<endl;
}
First: 3, Second: 5, Third: 2