调试时报错:无法从“std::string”转换为“char [10]”,怎么处理呢?
#include "stdafx.h"#include<string>
#include <iostream>
using namespace std;
class Student
{public:
Student(int n,string nam,char s)
{
num=n;
name=nam;
sex=s;
cout<<"Constructor called."<<endl;
};
~Student()
{
cout<<"Destructor called."<<endl;
}
void display()
{
cout<<"num:"<<num<<endl;
cout<<"name:"<<name<<endl;
cout<<"sex:"<<sex<<endl;
}
private:
int num;
char name[10];
char sex;
};
int main ( )
{
Student stud1(10010, "Wang_li",'f');
stud1.display();
Student stud2(10011, "Zhang_fa",'m');
stud2.display();
return 0;
}
调试时报错:无法从“std::string”转换为“char [10]”,怎么处理呢?