gpt4 book ai didi

c++ - 将Lambda传递给std::find

转载 作者:行者123 更新时间:2023-12-02 09:47:48 26 4
gpt4 key购买 nike

可能是一个深夜的挣扎,但我在这里遇到了一件简单的事情:

int main()
{
std::vector<int> v{1,2,3,4,5 };
int N;
std::cin>>N;
auto it = std::find(v.begin(), v.end(), [=](auto it)
{
return it*it == N;
});
}
我只想要第一个平方为N的值,并且编译器错误:
error C2678: binary '==': no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion)
请提示我在这里想念什么?

最佳答案

您需要find_if而不是find

关于c++ - 将Lambda传递给std::find,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63876280/

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