我制作了以下程序,其中有一个结构
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)
但是如果它在结构中,这会起作用吗?请帮忙。