lundi 20 janvier 2020

Can I use std::find() with lambda function in vc++ [VS 2019]?

  • OS: Windows 10 Pro 64-bit(10.0, build 18362)
  • IDE: Visual Studio 2019(Version 16.4.3) [Before this I was using VS 2010]
  • Language: c++ and VC++

Here's my simple code in which i just want to find element 3 and print it if found

    std::vector<int> intVect;

    for (int counter = 0; counter < 5; counter++)
    {
        intVect.push_back(counter);
    }

    std::find(intVect.begin(), intVect.end(), [](int a)
        {
            if (a == 3)
            {
                std::cout << "Item Found.." << std::endl;
            }
        });

The probelm is when i compile this code it's giving me error like below:

Error C2678 binary '==' : no operator found which takes a left-hand operand of type 'int' (or there is no acceptable conversion) c:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\include\algorithm 41

Aucun commentaire:

Enregistrer un commentaire