书上的题目,我改了一下就报错了(不知道怎么去改)求帮助
(Dev-C++上跑了一下)
#include<iostream> #include<cstring> using namespace std; const int L=100; class Person { private: char name[L],id[L]; public: Person() {} Person(char* N,char* I) { strcpy(name,N); strcpy(id,I); } friend istream& operator >>(istream& is,Person& pe); friend ostream& operator <<(ostream& os,Person& pe); }; istream& operator >>(istream& is,Person& pe) { cout<<"Please input the name:"; is>>pe.name; cout<<"Please input the id:"; is>>pe.id; return is; } ostream& operator <<(ostream& os,Person& pe) { cout<<"Name:"<<pe.name<<'\n'; cout<<"Id:"<<pe.id<<endl; return os; } int main() { Person object_1(),object_2("John","3012256"); cin>>object_1; cout<<object_1<<endl; cout<<object_2<<endl; return 0; }
报错是:[Error] cannot bind 'std::istream {aka std::basic_istream<char>}' lvalue to 'std::basic_istream<char>&&'
