- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个像这样的配对 vector
vector <pair<int , string> > Names;
我是这样放数据的:
cin>>taxi>>Ar_taxis>>Ar_mathiton;
for(j=0;j<Ar_mathiton;j++)
{
cin>>Ar_Mitroou>>Onoma;
Names.push_back(make_pair(Ar_Mitroou,Onoma));
}
我对它进行排序然后打印它:
for(j=0;j<Ar_mathiton;j++)
{
cout<<Names[i].first<<" "<<Names[i].second<<endl;
Names.pop_back();
}
我的 pop_back() 有问题,它没有删除 pair 的集合。我不知道是否还有其他命令可以执行此操作。谢谢。
[编辑]整个代码
cin>>Ar_taxeon;
for(i=0;i<Ar_taxeon;i++)
{
cin>>taxi>>Ar_taxis>>Ar_mathiton;
for(j=0;j<Ar_mathiton;j++)
{
cin>>Ar_Mitroou>>Onoma;
Names.push_back(make_pair(Ar_Mitroou,Onoma));
}
sort(Names.begin(),Names.end());
cout<<taxi<<Ar_taxis<<endl;
for(j=0;j<Ar_mathiton;j++)
{
cout<<Names[i].first<<" "<<Names[i].second<<endl;
Names.pop_back();
}
}
最佳答案
考虑以下更改:
将循环内变量i
的名称更改为j
你可以在 cout 之后调用 Names.clear(),而不是 Names.popBack():
所以你的最终代码将是:
#include <iostream>
#include <vector>
using namespace std;
int main(){
vector <pair<int , string> > Names;
int Ar_mathiton,Ar_Mitroou;
string Onoma;
cin>>Ar_mathiton;
for(int j=0;j<Ar_mathiton;j++)
{
cin>>Ar_Mitroou>>Onoma;
Names.push_back(make_pair(Ar_Mitroou,Onoma));
}
for(int j=0;j<Ar_mathiton;j++)
{
cout<<Names[j].first<<" "<<Names[j].second<<endl;
}
Names.clear();
return 0;
}
关于C++ : Pop_back a paired vector,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33308095/
来自 C++ Primer 以及 https://en.cppreference.com/w/cpp/container/priority_queue ,我知道: A priority_queue r
我有以下函数来计算两个笛卡尔点之间的距离,以及其中一个点关于 z 轴的镜像。 inline std::vector distances( MyCartesian const & point_i
我有以下创建 Stack 对象的主程序,用 double 填充它,然后弹出它们。代码文件很好,但 pop_back() 部分似乎不起作用,而 s.back() 确实返回了正确的值。这怎么可能? #in
为什么 pop_back() 没有返回值?我用谷歌搜索了一下,发现它可以提高效率。这是在标准中这样做的唯一原因吗? 最佳答案 效率与它几乎没有关系(或者根本没有关系)。 此设计是 an importa
为什么 pop_back() 没有返回值?我用谷歌搜索了一下,发现它可以提高效率。这是在标准中这样做的唯一原因吗? 最佳答案 效率与它几乎没有关系(或者根本没有关系)。 此设计是 an importa
为什么 pop_back() 没有返回值?我对此进行了谷歌搜索,发现它可以提高效率。这是在标准中这样做的唯一原因吗? 最佳答案 效率与它几乎没有关系(或者根本没有关系)。 这个设计是 an impor
我有一个像这样的配对 vector vector > Names; 我是这样放数据的: cin>>taxi>>Ar_taxis>>Ar_mathiton; for(j=0;j
列表.H void List::pop_back() { if (size == 0) cout next != NULL) iterator = it
如果有一个指针指向 vector 的最后一个元素,我想删除该元素但通过指针保留数据,我该怎么做? vector a; a.push_back(1); int * b = a[0]; a.pop_bac
给出下面的代码(假设它被命名为deque.cpp) #include #include int main() { std::deque d = {1, 2, 3}; for (auto i
std::string pop_back() : 移除字符串的最后一个元素 在 C++ 规范中说 C++11 字符串类函数 pop_back 具有常数时间复杂度。 (更准确地说 - 未指定但通常不变)
我在修改字符串时遇到问题。感谢您的协助;谢谢! struct Drawings::menues { std::vector variable; } Menue[numMenues]; Menu
我刚刚开始学习数据结构,并且正在实现某种数组列表(~=std::vector)。我想知道 pop_back() 是如何实现的,以便它具有恒定的复杂性?它必须将大小减少 1 并删除最后一个元素。现在我在
我有以下创建 Stack 对象的主程序,用整数填充它然后弹出它们。代码文件很好,但 pop_back() 部分似乎不起作用,即使在 pop_back() 打印所有值之后也是如此。这怎么可能? #inc
在下面的代码中,我实现了双向链表。我得到的输出为 56 2 3 4 0而不是 56 2 3 4 .但是,如果我删除 lt.erase(5); lt.push_back(46);然后我得到正确的输出。我
我目前正在自学 C++,但在创建析构函数时遇到了一些问题。 这是我正在努力处理的主要部分的代码 #include using namespace std; class Test { priv
这个问题在这里已经有了答案: When could std::priority_queue::pop throw an exception (1 个回答) 关闭 4 年前。 我很惊讶地看到标准 C+
所以我正在尝试为我的 Vector 类实现一个 pop_back() 函数,但我没有得到预期的结果: 这是我当前的功能: template void Vector::pop_back() {
代码: #include #include #include #include struct myClass { bool bIsDead; myClass(bool bDea
我试图理解 vector::pop_back() 的行为。所以我有以下代码片段: vector test; test.push_back(1); test.pop_back(); cout 0 的元
我是一名优秀的程序员,十分优秀!