小编Ben*_* Uy的帖子

在结构的向量中查找

我制作了以下程序,其中有一个结构

struct data
{
   int integers; //input of integers
   int times; //number of times of appearance
}
Run Code Online (Sandbox Code Playgroud)

并且有这个结构的向量

std::vector<data> inputs;
Run Code Online (Sandbox Code Playgroud)

然后我会从一个文件中得到一个整数 current_int

std::fstream openFile("input.txt")
int current_int; //current_int is what I want to check if it's in my vector of struct (particularly in inputs.integers)
openFile >> current_int;
Run Code Online (Sandbox Code Playgroud)

我想检查 current_int 是否已经存储在我的向量输入中。我试过研究在向量中查找数据,据说你使用这样的迭代器:

it = std::find(inputs.begin(),inputs.end(),current_int)
Run Code Online (Sandbox Code Playgroud)

但是如果它在结构中,这会起作用吗?请帮忙。

c++ struct vector find

1
推荐指数
1
解决办法
2890
查看次数

标签 统计

c++ ×1

find ×1

struct ×1

vector ×1