0

Brand new (as of ten minutes ago) to stack overflow and (about a week in) c++, but I'm working on trying to get a library management system I found online working to see how classes work. I found the original code here: https://www.icbse.com/projects/c-project-on-library-management-2g and am trying to figure out how to get it to run. Some of the headers are a bit old so I updated and made changes as needed. Ran into an issue with get() and saw someone on here said that's bad practice/unsafe so I changed all of those references to 'std::getline'. However, I now have an issue I haven't been able to solve why my debugger has the squiggle under std. I get 'no instance of overloaded function "std::getline" matches the argument list -- argument types are: (std::istream, char [50])'. I'm not sure how to fix this issue. Any help would be appreciated.

#include<iostream>
#include<fstream>
#include<conio.h>
#include<stdio.h>
#include<stdlib.h>
#include<process.h>
#include<string.h>
#include<iomanip>
#include<string>

using namespace std;
using std::cout;
using std::getline;

class book
{
    char bno[6];
    char bname[50];
    char aname[20];
  public:
    void create_book()
    {
        cout<<"\nNEW BOOK ENTRY...\n";
        cout<<"\nEnter The book no.";
        cin>>bno;
        cout<<"\n\nEnter The Name of The Book ";
        std::getline(std::cin, bname);
        cout<<"\n\nEnter The Author's Name ";
        std::getline(std::cin,aname);
        cout<<"\n\n\nBook Created..";
    }

    void show_book()
    {
        cout<<"\nBook no. : "<<bno;
        cout<<"\nBook Name : ";
        puts(bname);
        cout<<"Author Name : ";
        puts(aname);
    }

    void modify_book()
    {
        cout<<"\nBook no. : "<<bno;
        cout<<"\nModify Book Name : ";
        std::getline(std::cin,bname);
        cout<<"\nModify Author's Name of Book : ";
        std::getline(std::cin,aname);
    }

    char* retbno()
    {
        return bno;
    }

    void report()
    {cout<<bno<<setw(30)<<bname<<setw(30)<<aname<<endl;}


};
  • Review [Why is “using namespace std;” considered bad practice?](https://stackoverflow.com/q/1452721/364696) and you only need 3 headers, `iostream`, `iomanip` and `string`. Change to `string bno;`, etc.. Change `puts()` to `cout << "\nBook Name : " << bname;`, etc.. and `string retbno()` – David C. Rankin Apr 25 '20 at 17:36

1 Answers1

1

std::getline(std::cin, bname); -> std::cin.getline(bname, 50);.

Global function std::getline() only works with std::basic_string type. Member function getline() only works with char[].

Or you can save yourself future trouble and change char[] to std::string. It's much easier to use overall.


Be aware that mixing getline() and >> is problematic.

Yksisarvinen
  • 13,037
  • 1
  • 18
  • 42