-5

The full error message reads:

Error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'std::_Vector_iterator< std ::_Vector_val < std::_ Simple _ types < projects > > >' (or there is no acceptable conversion)

Not the prettiest but here's my code up to the error, with the getters and setter functions happening elsewhere, but they don't seem important to this error:

#include "Project.hpp"
#include <iostream>
#include <sstream>
#include <string>
#include <fstream>
#include <list>
#include <ostream>
#include <stdlib.h>
using namespace std;

int main(){


cout << "Welcome to our project topic allocator, please enter the student spreadsheet; " << endl;
vector<student> studentvector;
vector<projects> projectsvector;
vector<projects> availchoicevector;

//string excelsupervisor;
//supervisor staff;

string excelstudent;
student pupil;

string excelprojects;
projects selections;

selections.zbbb(excelprojects);
//pupil.xbbb(excelstudent);
//staff.ybbb(excelsupervisor);
int counter;


vector<student>::iterator first1 = studentvector.begin(), last1 = studentvector.end(), fileline1;

vector<projects>::iterator first2 = projectsvector.begin(), last2 = projectsvector.end(), fileline2;

for (fileline1 = studentvector.begin(), fileline2 = projectsvector.begin(); fileline1 != studentvector.end(), fileline2 != projectsvector.end(); fileline1++, fileline2++){

    cout << "Student ID      " << fileline1->get_studentname() << endl;
    int var1 = fileline1->get_numberofselections();

    if (var1 = !4){

        cout << "Student has not made 4 choices, consult student!" << endl;
        fileline2 = fileline2 + (var1 - 1);
        continue;
    }
    else{
        //for (fileline2; fileline2 < fileline2 + 4; fileline2++){
        const auto &p = fileline2->get_projectID(); //fileline2 = 1st choice
        auto y = find(availchoicevector.begin(), availchoicevector.end(), p);
        if (y != availchoicevector.end()){
            cout << "Project ID . Supervisor ID of allocated choice:    " << *y << "." << fileline2->get_supervisorIDproj << endl;}

With the error occurring on the last line at the "<<" before the "*y".

Here's the header that corresponds to this part of the code.

class projects{

private: 
string projectname, projectsup, supervisornameproj, stunameproj;
float projectID;
int itterator, rank, classs, supervisorIDproj, stuIDproj, regnumproj;



public:





projects();
~projects();
void set_projectname(string);
void set_supervisornameproj(string);
void set_stunameproj(string);

void set_stuIDproj(int);
void set_supervisorIDproj(int);
void set_projectID(int);
void set_regnumproj(int);
void set_rank(int);
void set_classs(int);


string get_projectname(){return projectname;}
string get_stunameproj(){return stunameproj;}
string get_supervisornameproj(){return supervisornameproj;}     

int get_regnumproj(){return regnumproj;}
int get_supervisorIDproj(){return supervisorIDproj;}
int get_stuIDproj(){return stuIDproj;}
int get_projectID(){return projectID;}
int get_rank(){return rank;}
int get_classs(){return classs;}


bool zbbb(string);
bool sorting(int);

vector<projects> projectsvector;
vector<projects> availchoicevector;
};

I wish to know how to resolve this matter. I understand I should overload the << operator but I have no idea how to do it for this case!

Any help would be greatly appreciated!

Matthew
  • 13
  • 2
  • [How do I ask a good question?](http://stackoverflow.com/help/how-to-ask) "Include just enough code to allow others to reproduce the problem. For help with this, read [How to create a Minimal, Complete, and Verifiable example.](http://stackoverflow.com/help/mcve)". "When asking a question about a problem caused by your code, you will get much better answers if you provide code people can use to reproduce the problem." – Mooing Duck Apr 27 '15 at 18:41
  • 2
    You need to overload the `operator <<` for the projects class. Here is an [MSDN](https://msdn.microsoft.com/en-us/library/1z2f6c2k.aspx?f=255&MSPPError=-2147217396) example – NathanOliver Apr 27 '15 at 18:42
  • 1
    Well, the compiler error message is pretty clear. If you want to have this functionality, you'll need to provide your own implementation. I doesn't come out of the box. – πάντα ῥεῖ Apr 27 '15 at 18:42
  • I think you have missed the last part. "I understand I should overload the << operator but I have no idea how to do it for this case!" – omerfarukdogan Apr 27 '15 at 18:49

1 Answers1

1

You must overload operator<< between an ostream object and your own object.

ostream &operator<<(ostream &output, const projects &prj)
{
    //print something you want of prj with output << ...
    return output;
}

Also, you need to add this friend definition to your class if the overloaded operator needs to access its private data members:

friend ostream &operator<<(ostream &, const projects &);

You can't overload the operator as a member method, because the function is actually used on an ostream object, not on your object.

omerfarukdogan
  • 839
  • 9
  • 26