无法将int转换为int *

时间:2014-09-16 10:22:40

标签: c++ char int

我是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. 调用__s时参数gets(char*)中的类型不匹配。
  3. 这两个错误都在gets(GSize);行 如何纠正错误?

1 个答案:

答案 0 :(得分:1)

首先,搜索不适合您的功能并阅读并了解它们。在这种情况下:gets

&#34; get string&#34;的缩写。 int是一个int。不是字符串!