函数中的声明语法错误

用户名

请帮助我解决这个问题,即使我在学校输入了代码,即使它显示了声明语法错误。-.-无法解决!当您刚开始学习编码时,它是如此令人沮丧。

无效的问题错误:声明语法错误无效的显示错误:指针的非法使用

抱歉,如果发现我有任何愚蠢的行为。

#include <iostream.h>
#include <conio.h>
#include <stdio.h>
#include <string.h>


class book
{
char bookname[20];
char isbn[20];
char author[20];
char category[20];
float price;
int noc;

public:

void accept()
{

cout<<"Enter book name :- \n";
gets(bookname);
cout<<"Enter isbn no of the book:- \n";
gets(isbn);
cout<<"Enter authour name:- \n";
gets(author);
cout<<"Enter category of book:- \n";
gets(category);
cout<<"Enter price of the book :- \n";
cin>>price;
cout<<"Enter no of copies of book available in the library :- \n";
cin>>noc;
}

void display()
{
puts(bookname)<<endl;
puts(isbn)<<endl;
puts(author)<<endl;
puts(category)<<endl;
cout<<price<<endl;
cout<<noc<<endl;
}

}b[5];

int main()
{
for(int i=0;i<5;++i)
{
b[i].accept();
}

void issue()
{
int flag=0;
char booksearch[20];
cout<<"Enter name of book member wants to issue :- \n"
gets(booksearch);
  for(i=0;i<5;++i)
  {
      flag=strcmp(booksearch,b[i].bookname)
  }

}

 if(flag==1)
 {
   b[i].display();
   b[i].issue();
 }
 getch();
 return 0;
 }

您的代码有很多错误:

  1. strcmp通话后缺少分号
  2. strcmp 如果存在匹配项,则返回0,而不是1,并且您可能在循环的下一次迭代中覆盖标志,
  3. 您对的定义issue位于的中间main
  4. 您正在混合使用c风格的gets和c ++风格的运算符>>,
  5. 您正在混合-非常糟糕-C风格的看跌期权和操作员<<

这是您的代码的无效版本:http : //ideone.com/sGdXcm

这是一个固定的工作版本:

#include <iostream>
#include <string>
#include <array>
#include <limits>

using namespace std;

class book
{
    std::string bookname;
    std::string isbn;
    std::string author;
    std::string category;
    float price;
    int noc;

public:
    const std::string& getBookname() const { return bookname; }
    const std::string& getISBN() const { return isbn; }
    const std::string& getAuthor() const { return author; }
    const std::string& getCategory() const { return category; }
    float getPrice() const { return price; }
    float getNoC() const { return noc; }

    void accept()
    {
        cout<<"Enter book name :- \n";
        std::getline(std::cin, bookname);
        cout<<"Enter isbn no of the book:- \n";
        std::getline(std::cin, isbn);
        cout<<"Enter authour name:- \n";
        std::getline(std::cin, author);
        cout<<"Enter category of book:- \n";
        std::getline(std::cin, category);
        cout<<"Enter price of the book :- \n";
        std::cin>>price;
        cout<<"Enter no of copies of book available in the library :- \n";
        std::cin>>noc;
        std::cin.ignore(std::numeric_limits<streamsize>::max(), '\n');
    }

    void display()
    {
        std::cout<<bookname<<std::endl;
        std::cout<<isbn<<std::endl;
        std::cout<<author<<std::endl;
        std::cout<<category<<std::endl;
        std::cout<<price<<std::endl;
        std::cout<<noc<<std::endl;
    }

    void issue()
    {
    }
};

int main()
{
    std::array<book, 5> b;
    for(int i=0;i<b.size();++i)
    {
        b[i].accept();
    }

    std::string booksearch;
    std::cout<<"Enter name of book member wants to issue :- \n";
    std::getline(cin, booksearch);
    std::cout<<"Searching for: " << booksearch << "\n";
    for(int i=0;i<b.size();++i)
    {
        if (b[i].getBookname() == booksearch)
        {
            b[i].display();
            b[i].issue();
            break;
        }
    }

    std::string dummy;
    std::cout << "Hit return:";
    std::getline(std::cin, dummy);

    return 0;
}

现场演示:http//ideone.com/p3Ygw3

注意:我没有在此代码中添加任何错误检查,如果用户在输入书籍时输入错误,则会出错。

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

函数中的OCaml语法错误

来自分类Dev

mariadb声明变量语法错误

来自分类Dev

数据声明中的fortran循环语法错误

来自分类Dev

函数中if语句的Postgresql语法错误

来自分类Dev

语法错误:函数主体外部的非声明语句

来自分类Dev

我函数中的Haskell语法错误

来自分类Dev

在bash中,函数内部的Heredoc返回语法错误

来自分类Dev

C结构声明中的SWIG语法错误

来自分类Dev

js函数中的“语法错误,意外令牌=”

来自分类Dev

箭头函数返回的对象中的“意外令牌”语法错误

来自分类Dev

语法错误:在const声明Firefox 50中缺少=

来自分类Dev

语法错误在MariaDB的声明变量

来自分类Dev

尝试在sql中声明变量并使用if-else语句时出现语法错误。-“ VARCHAR”或附近的语法错误

来自分类Dev

声明postgres变量时的语法错误

来自分类Dev

在C中的变量声明上获取语法错误

来自分类Dev

java JApplet声明语法错误

来自分类Dev

递归函数中的OCaml语法错误

来自分类Dev

布尔声明的语法错误

来自分类Dev

SQL创建函数中的语法错误

来自分类Dev

语法错误:丢失;声明jsonp之前

来自分类Dev

我的函数中的Haskell语法错误

来自分类Dev

函数中的Postgres语法错误

来自分类Dev

声明中的语法错误

来自分类Dev

PHP中的函数语法错误

来自分类Dev

函数中的声明语法错误

来自分类Dev

语法错误:缺少; 声明前

来自分类Dev

嵌套函数中的Ocaml语法错误

来自分类Dev

函数定义的语法错误

来自分类Dev

VHDL 通用组件声明语法错误