如何解决我的函数无法获得“名称”,我应该如何使用字符?
我正在尝试创建一个布料数据库,但我遇到了字符“createtshirt”函数无法获取“名称”的问题,编译器给出错误消息“进程已完成,退出代码为 -1073741819 (0xC0000005)”。
#include <iostream>
using namespace std;
#include "cmake-build-debug/types.h"
#include "cmake-build-debug/functions.h"
int main() {
tshirt model1;
/*model1.name=(char*) "mx15";
model1.color=3;
model1.size=5;
model1.price=49.99;*/
createtshirt(model1);
cout<<model1.name<<model1.color<<model1.size<<model1.price;
}
types.h
//
// Created by corifect- on 11.07.2021.
//
#ifndef CLOTHDATABASE_PROJECT2_TYPES_H
#define CLOTHDATABASE_PROJECT2_TYPES_H
#endif //CLOTHDATABASE_PROJECT2_TYPES_H
class tshirt{
public:
char* name;
int size;
int color;
double price;
};
函数.h
//
// Created by corifect- on 11.07.2021.
//
#ifndef CLOTHDATABASE_PROJECT2_FUNCTIONS_H
#define CLOTHDATABASE_PROJECT2_FUNCTIONS_H
#endif //CLOTHDATABASE_PROJECT2_FUNCTIONS_H
void createtshirt(tshirt &x){
cout<<"please enter name of new model\n";
cin>>(char*)x.name;
cout<<"please enter size of new model\n";
cin>>x.size;
cout<<"please enter color of new model\n";
cin>>x.color;
cout<<"please enter price of new model\n";
cin>>x.price;
}
Jetbrains Clion 2021.1.2 x64 学生版 C++14
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。