【C++】VS2017 不能将const char * 分配给 char *

我的方式是把结构体中定义的 char * 换成string

#include <iostream>
#include<string>
using namespace std;

class Student {
public:
    void setname(string name);
    void setage(int age);
    void setscore(float score);
    void show();
private:
    string name;
    int age;
    float score;
};

void Student::setname(string name) {
    this->name = name;
}
void Student::setage(int age) {
    this->age = age;
}
void Student::setscore(float score) {
    this->score = score;
}
void Student::show() {
    cout << this->name << "的年龄是" << this->age << ",成绩是" << this->score << endl;
}

int main() {
    Student *pstu = new Student;
    pstu->setname("小明");
    pstu->setage(18);
    pstu->setscore(100.0);
    pstu->show();

    return 0;
}
上一篇:QT界面开发-在VS2017环境下Qt读写Excel遇到"无法打开 源 文件 'QAxObject'"的错误解决办法【转载】


下一篇:VS2017+Qt5.12