Search code examples
c++arrayspointersstdvector

How to compare vector<float> and float*


I need to compare two float arrays for equality of their values. I know they have the same length. But unfortunately the arrays are not the same type:

bool compare(vector<float> A, float* B) 
{
  // what do I write here?
}

How can I do it? I am not that familiar with pointers.


Solution

  • Thanks a lot everybody! This is how I did it now, since I know that the two vectors have the same length.

    bool compareSerAndPar(std::vector<float> Ser, float* Par, int size)
    {
        float eps = 0.01f;
        
        for(int i = 0; i < size; i++)
        {
            float temp = fabs(Ser[i] - Par[i]);
            if(temp > eps)
            {
            return false;
            }
        
        }
        return true;
    }