![]() |
#2
zoufengrui2012-12-24 17:08
嗯嗯嗯,错了,是
#include<iostream> #include<cstring> using namespace std; class Employee{ public: Employee(string* Name,string* City,string* Address,string* Postcode){ strcpy(Name,N); strcpy(Address,A); strcpy(City,C); strcpy(Postcode,P);; ~Employee(){}; void display(){}; void chang_name(string* Name,string* City,string* Address,string* Postcode){}; private: string Name; string City; string Address; char Postcode; }; void Employee::display(){ cout<<"Name: "<<Name<<" City: "<<City<<" Address: "<<" Postcode: "<<endl; } void Employee::chang_name(string Name,string City,string Address,string Postcode){ cout<<"Please enter the name:"<<endl; cin>>Name; cout<<"Please enter the city:"<<endl; cin>>City; cout<<"Please enter the address:"<<endl; cin>>Address; cout<<"Please enter the postcode:"<<endl; } int main(){ int i; Employee *people=new Employee[5]; for(i=0;i<6;i++){ cout<<"Please inter the "<<(i+1)<<"'s information"<<endl; Employee[i].change_name(); } for(i=;i<6;i++){ cout<<"the result is:"<<endl; Employee[i].display(); } return 0; } 这里报错:: error C2664: 'strcpy' : cannot convert parameter 1 from 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >' to 'char *' |
#include<iostream>
#include<cstring>
using namespace std;
class Employee{
public:
Employee(string* Name,string* City,string* Address,string* Postcode){
strcpy(Name,N);
strcpy(Address,A);
strcpy(City,C);
strcpy(Postcode,P);;
~Employee(){};
void display(){};
void chang_name(string* Name,string* City,string* Address,string* Postcode){};
private:
string Name;
string City;
string Address;
char Postcode;
};
void Employee::display(){
cout<<"Name: "<<Name<<" City: "<<City<<" Address: "<< Postcode: "<<endl;
}
void Employee::chang_name(string Name,string City,string Address,string Postcode){
cout<<"Please enter the name:"<<endl;
cin>>Name;
cout<<"Please enter the city:"<<endl;
cin>>City;
cout<<"Please enter the address:"<<endl;
cin>>Address;
cout<<"Please enter the postcode:"<<endl;
}
int main(){
int i;
Employee *people=new Employee[5];
for(i=0;i<6;i++){
cout<<"Please inter the "<<(i+1)<<"'s information"<<endl;
Employee[i].change_name();
}
for(i=;i<6;i++){
cout<<"the result is:"<<endl;
Employee[i].display();
}
return 0;
}
机器在编译时在display()函数处报错,说是newline in constant,这是什么情况??还有,我这样写程序可以么???