0

hi:
I have a trouble on the codes below, if I were to insert string n into the following string "Constructing student" ,the compile would appear error C2679. I don't know where any error the code have.

error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' (or there is no acceptable conversion)

#include<iostream>

using namespace std;

class StudentID{

    int value;

public:
	StudentID(){

     static int nextStudentID = 0;
	 value = ++nextStudentID;
	 cout << "Assigning student id "<<value<<endl;

	}


};

class Student{

    string name;
	StudentID id;

public:
	Student(string n = "noName"){
     cout << "Constructing student " <<n<<endl; //error C2679
	 name = n;
	 

	}


};

void main(){
    
	Student s("Randy");

}
2
Contributors
1
Reply
2
Views
6 Years
Discussion Span
Last Post by Ancient Dragon
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.