Search code examples
c++stdstdlist

error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘std::_List_iterator<int>’)


Hello im trying to print a list of ints and i keep getting that erro.

I have a structure that have a list on it.

struct faceFiguration{

    int faceID;
    list<int> setofVertices;

};

And i have a list of that sructure

 list<faceFiguration> pattern;

and heres where i get confuse, i trie to print the lists here:

void PrintFaces(){

      currentFace = pattern.begin();
      while(currentFace != pattern.end()){

        cout << currentFace -> faceID << endl;

        for(auto currentVertices = currentFace->setofVertices.begin(); currentVertices != currentFace->setofVertices.end(); currentVertices++){

          cout << currentVertices;

        }

        cout << '\n';
        currentFace++;
      }

    }

This is the full message error

error: no match for ‘operator<<’ (operand types are ‘std::ostream’ {aka ‘std::basic_ostream<char>’} and ‘std::__cxx11::list<int>’)


Solution

  • You've already gotten answers telling you to dereference the iterator:

    for(auto currentVertices = currentFace->setofVertices.begin();
        currentVertices != currentFace->setofVertices.end();
        currentVertices++)
    {
        cout << *currentVertices;   // dereference
    }
    

    You could however do that automatically by using a range-based for loop:

    for(auto& currentVertices : currentFace->setofVertices) {
        cout << currentVertices;    // already dereferenced
    }