无法将int转换为int*

Cannot convert int to int*

本文关键字:int 转换      更新时间:2023-10-16

我是C++的初学者,想创建一个名为"Garment"的类,我在其中编码:

#include<iostream.h>
#include<conio.h>
#include<string.h>
#include<stdio.h>
class Garments
{
    char GCode[15];
    char GType[15];
    int GSize;
    char GFabric[15];
    float GPrice;
    void Assign() {
        if(strcmp(GFabric,"COTTON")==0) {
            if(strcmp(GType,"TROUSER")==0)
                GPrice=1300;
            else if(strcmp(GType,"SHIRT")==0)
                GPrice=1100;
        } else {
            if(strcmp(GType,"TROUSER")==0)
                GPrice=1300-0.10*1300;
            else if(strcmp(GType,"SHIRT")==0)
                GPrice=1100-0.10*1100;
        }
    }
public:
    Garments() {
        strcpy(GCode,"NOT ALLOWED");
        strcpy(GType,"NOT ALLOWED");
        strcpy(GFabric,"NOT ALLOWED");
        GSize=0;
        GPrice=0;
    }
    void Input() {
        cout<<"Enter Garment Code:";
        cin>>GCode;
        cout<<"nEnter Garment Type(TROUSER/SHIRT)";
        cin>>GType;
        cout<<"nEnter Garment Size:";
        gets(GSize);
        cout<<"nEnter Garment Fabric:";
        gets(GFabric);
        Assign();
    }
    void Display() {
        cout<<"Garment Code:"<<GCode;
        cout<<"nGarment Type:"<<GType;
        cout<<"nGarment Size:"<<GSize;
        cout<<"nGarment Fabric:"<GFabric;
        cout<<"nGarment Price:"<<GPrice;
    }
};
void main()
{
    clrscr();
    Garments G;
    G.Input();
    G.Display();
    getch();
}

上面的代码正确吗?在Turbo C++中编译时,我有两个错误:

  1. 无法将int转换为char*
  2. 在对gets(char*)的调用中,参数__s的类型不匹配

两个错误都在gets(GSize);行如何更正错误?

首先,搜索不适合您的函数,阅读并理解它们。在这种情况下:获取

它是"获取字符串"的缩写。int就是int,而不是字符串!