dev gets() & puts() 未在 dev C++ 的范围内声明
dev gets() & puts() not declared in scope in dev c++
这是我为书店编写的简单代码代码没有任何问题。我使用DevC++来运行代码,编译后它会发出一个错误,说"gets"没有在这个范围内声明&看跌期权也有同样的错误。请帮帮我。
#include<iostream>
#include<conio.h>
#include<stdlib.h>
#include<iomanip>
#include<cstring>
using namespace std;
class Book
{
char *title,*author,*publisher,ans;
int price,quant,quant_ent;
public:
Book()
{
title = new char[50];
author = new char[50];
publisher = new char[50];
price = quant = quant_ent = 0;
}
void getdata()
{
cout<<"nEnter The Title";
gets(title);
cout<<"nEnter The Author";
gets(author);
cout<<"nEnter The Publisher";
gets(publisher);
cout<<"nEnter The Price";
cin>>price;
cout<<"nEnter The Quantity";
cin>>quant;
}
void display()
{
cout<<setw(15)<<title<<setw(15)<<author<<setw(15)<<publisher<<setw(10)<<quant
<<setw(10)<<price;
}
void search(char search_title[],char search_author[])
{
if(strcmpi(author,search_author)==0)
{
if(strcmpi(title,search_title)==0)
{
cout<<"nBook Found!";
cout<<"nEnter The Quantity: ";
cin>>quant_ent;
if(quant_ent <= quant)
{
cout<<"nThe Title is: ";
puts(title);
cout<<"nThe Author is: ";
puts(author);
cout<<"nThe Publisher is: ";
puts(publisher);
cout<<"nPrice Of Single Copy: "<<price;
cout<<"nTotal Price = "<<price*quant_ent;
quant = quant - quant_ent;
}
else
{
cout<<"nSufficient Quantity Not Available!";
}
}
}
}
};
int main()
{
Book obj[10];
int i=0,ch;
char author[50],title[50];
for(;;)
{
cout<<"n*******MENU********n1)Enter Detailsn2)Buy Bookn3)Display All Booksn4)Exit";
cin>>ch;
switch(ch)
{
case 1:
obj[i].getdata();
i++;
break;
case 2:
cout<<"nEnter The Authors Name: ";
gets(author);
cout<<"nEnter The Title: ";
gets(title);
for(int j=0;j<i;j++)
{
obj[j].search(title,author);
}
break;
case 3:
cout<<setw(15)<<"TITLE"<<setw(15)<<"AUTHOR"<<setw(15)<<"PUBLISHER"<<setw(15)<<"QUANTITY"<<setw(15)<<"PRICE";
cout<<"n"<<setw(75)<<"-----------------------------------------------------------------------------------------------------";
for(int j=0;j<i;j++)
{
cout<<"n";
obj[j].display();
}
case 4:
exit(1);
};
}
}
因为它是在stdio.h
(C++中的cstdio
)标头中声明的,而您还没有包含它。
但您不能使用gets
。这是一个无可救药的坏功能。请改用fgets
。更好的是,去掉指向char数组的裸指针,改为使用std::string
类。
相关文章:
- .cpp和.h文件中的模板专用化声明
- 未在作用域中声明unordered_map
- C++避免重复声明的语法是什么
- 如何确保C++函数在定义之前声明(如override关键字)
- 错误:未在此范围内声明'reverse'
- 奇怪的(对我来说)返回声明 - 在谷歌上找不到任何关于它的信息
- 为什么在定义函数之前先声明它
- 如何声明特征矩阵,然后通过嵌套循环初始化它
- #ifdef和未声明的标识符
- 没有显式声明的int[]中的foreach
- 在基于范围的for循环中使用结构化绑定声明
- 在将变量声明为引用时,堆在释放后使用
- C++:无法访问声明的受保护成员
- 为什么我不能在一个类的不同行中声明和定义成员变量?
- 我不明白为什么我声明一个空的内部结构并将其传递给构造函数
- 使用cmake从源代码构建MySQL连接器/C++失败(与以前的声明冲突)
- 在函数内部的声明中初始化数组,并在外部使用它
- 非整数常量声明 - dev-error:在此范围内未声明"type"
- 为什么 dev C 不运行此脚本?由于某种原因不喜欢我的矢量声明
- dev gets() & puts() 未在 dev C++ 的范围内声明