strcpy(name,nm);这里出现了警告,怎么解决?

#include"iostream"
using namespace std;
class student
{
private:
char name[18];
int num;
int mathScore;
int englishScore;
static int count;
static int mathTotalScore;
static int englishTotalScore;
public:
student(char *nm,int nu,int math,int english):num(nu),mathScore(math),englishScore(english){
strcpy(name,nm);
count++;
mathTotalScore+=mathScore;
englishTotalScore+=englishScore;
}
void bshow()
{
cout << name << " " << num << " " << mathScore << " " << englishScore << endl ;
}

static void show(){
    cout << count << "  " << mathTotalScore << "  " << englishTotalScore << endl ;
};

};

int student::mathTotalScore=0;
int student::englishTotalScore=0;
int student::count=0;

void main()
{
student s("liu",1,60,60),t("pan",2,60,60);
s.bshow();
t.bshow();
student::show();

}

strcpy是不安全的函数,所以有警告很正常,用安全的版本strncpy或者strcpy_s

因为这个函数是不是个安全函数,可能造成缓冲区溢出!你可以试一试这个方法:
把strcpy换成strcpy_s