gpt4 book ai didi

c++ - C++ vector 使用错误 : No matching member function for call to 'push_back'

转载 作者:行者123 更新时间:2023-11-30 03:16:45 25 4
gpt4 key购买 nike

我基本上是在尝试使用 vector ,但它有一个问题。顺便说一句,我要解决的问题是 USACO 2014 年 12 月铜牌问题 #4。代码在下面。

#include <iostream>
#include <cstring>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
int num,min,max;
cin>>num>>min>>max;

vector <pair<int,int> > cow;

for(int a=0;a<num;num++)
{
int temp;
int temp2;
cin>>temp>>temp2;

cow.push_back (temp2);

if(temp=="NS")
cow[a].second=0;
else if(temp=="S")
cow[a].second=1;
}

sort(cow.begin(),cow.end());

int count=0;

cout<<"Count="<<count<<endl;

for(int b=0;b<num;b++)
{
cout<<"Weight: "<<cow[b].first;
if(cow[b].second==0)
cout<<"Spots: NO"<<endl;
else if(cow[b].second==1)
cout<<"Spots: YES"<<endl;
}
}

预期的结果应该是vector应该按数字顺序排列,但是我卡在了第一步。此外,它给我的错误是:没有匹配的成员函数来调用“push_back”

我不知道如何处理这个问题,而且我也找不到任何关于类似问题的在线资源。有人可以帮忙吗?

*编辑:将 int temp 更改为 string temp

最佳答案

您声明了一个对 vector ,但将一个 int 推回到 vector 中

关于c++ - C++ vector 使用错误 : No matching member function for call to 'push_back' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56023385/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com