无法将int转换为int*
Cannot convert int to 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++中编译时,我有两个错误:
- 无法将
int
转换为char*
- 在对
gets(char*)
的调用中,参数__s
的类型不匹配
两个错误都在gets(GSize);
行如何更正错误?
首先,搜索不适合您的函数,阅读并理解它们。在这种情况下:获取
它是"获取字符串"的缩写。int就是int,而不是字符串!
相关文章:
- 是否可以从int转换为enum类类型
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 是什么导致了这种使用三进制而不是短整型的有符号int到无符号int转换
- 将字符串中的 int 转换为字母;
- 主.cpp:18:20:错误:从"int*"转换为"int"会失去精度 [-fa
- 将非常大的 int 转换为双倍,在某些计算机上会损失精度
- 如何将矢量<int>转换为字符数组?
- C++ 无法从 const int* 转换为 const_iterator
- 我不断收到错误 C2440'=':无法从"int *(__cdecl *)(int *,int *,int,int)"转换为"int *
- 如何将 int[4] 转换为 std::array<int,4>?
- 如何将data[i].int转换为vaible
- 将 int 转换为字符串,然后连接另一个变量以创建完整扩展名,然后将其转换为 const_char*
- 将私有矩阵形式 int 转换为双 C++
- 无法将参数 1 从 'int' 转换为 'int &'
- 将 int 转换为字符串后始终得到 0
- isspace 函数的性能警告,从 int 转换为布尔值
- 将大 int 转换为浮点数,而不舍入 c++
- 错误:无法将'uint8* {aka unsigned int*}'转换为"常量emxArray_uint8_T*"?
- 将未签名的INT转换为BCD
- 在 C++ 中将 int 转换为双精度