newbie need help w/error messages

This is a discussion on newbie need help w/error messages within the C++ Programming forums, part of the General Programming Boards category; I need help with 5 error messages. I'm new at c++ so I don't understand what these errors mean or ...

  1. #1
    Registered User
    Join Date
    Oct 2001
    Posts
    23

    newbie need help w/error messages

    I need help with 5 error messages. I'm new at c++ so I don't understand what these errors mean or I don't see what I did wrong.

    Script started on Tue Dec 04 17:01:36 2001
    strauss.udel.edu% cat librar          cat library.h

    //header file for library class



    #ifndef Library_H

    #define Library_H

    #include "book.h"

    #include "card.h"

    #include <fstream.h>

    #include <iostream.h>



    class Library {

    private:

    char command;

    static int num_books;

    static int num_cards;

    Book *books[100];

    Card *cards[100];

    void printcards();

    void printbooks();

    void checkout();

    void checkin();

    public:

    Library(ifstream &input);

    ~Library();

    void DoCommand(char);

    Book* Findbook(int);

    Card* Findcard(int);

    static int getnum_books;

    static int getnum_cards;

    };



    #endif

    strauss.udel.edu% cat libraray  y.cc

    //member definition for library class



    #include "book.h"

    #include "card.h"

    #include "library.h"

    #include <string.h>

    #include <fstream.h>

    #include <iostream.h>



    Library :: Library(ifstream &input) {

    Book *book;

    Card *card;

    char title[100];

    char author[100];

    char name[100];

    char phone[100];

    int BookID;

    int BID;

    int CardID;

    int CID;

    int status;

    int i =0, j = 0;



    input.getline(title, 100);

    for(int i = 0; i < 100; i++) {

    books[i] = NULL;

    i = 0;

    while(strcmp(title, $$$) != 0) {

    input.getline(author, 100);

    input >> BookID >> status >> CID;

    books[i] = new Book(title, author, BookID, status, CID);

    num_books++;

    input.ignore();

    input.getline(title, 100);

    i++;

    }

    }



    input.getline(name, 100);

    for(int j = 0; j < 100; j++) {

    cards[j] = NULL;

    j = 0;

    while(!input.eof()) {

    input.getline(phone, 100);

    input >> CardID >> BID;

    cards[j] = new Card(name, phone, CardID, BID);

    num_cards++;

    input.ignore();

    input.getline(name, 100);

    j++;

    }

    }

    }

    Book* Library :: Findbook(int b) {

    int i = 0;

    while(books[i] != NULL) {

    if(books[i]->getBookID() == b)

    return books[i];

    else

    i++;

    }

    cout >> "Book not found";

    return NULL;

    }

    Card* Library :: Findcard(int c) {

    int j = 0;

    while(!input.eof()) {

    if(cards[j]->getCardID() == c)

    return cards[j];

    else

    j++;

    }

    cout >> "Card not found";

    return NULL;

    }

    void Library :: DoCommand(char c) {

    command = c;

    int i = 0, j = 0, BookID, CardID;



    if(command = 'B'){

    while(books[i] != NULL) {

    cout << "Processing book - ";

    books[i]->print() ;

    cout << endl;

    i++;

    }

    cout << num_books << "books in the library" << endl;

    }else if(command = 'C') {

    while(cards[j] != NULL) {

    cout << "Processing card - ";

    cards[j]->print();

    cout << endl;

    j++;

    }

    cout << num_cards << "cards in the library" << endl;

    }else if(command = 'O') {

    cout << "Enter book ID: ";

    cin >> BookID;

    Findcard(CardID);

    cout << "Enter card ID: ";

    cin >> CardID;

    Findbook(BookID);



    if(books[i]->getBookID() != 0) {

    cout << "Sorry. You can't check out a book until"

    << "you return the book that you checked out"

    << "before." << endl;

    }else {

    if(books[i]->getstatus() == 0) {

    books[i]->setstatus(1);

    cards[j]->setBookID(BookID);

    books[i]->setCardID(CardID);

    }else if(books[i]->getstatus() == 1) {

    cout << "Sorry, but the has already been"

    << "checked out."<< endl;

    }else {

    cout << "Book is at the bindery."<< endl;

    }

    }

    }else if(command = 'W') {

    cout << "Enter book ID: ";

    cin >> BookID;

    Findbook(BookID);

    cout << "Enter card ID: ";

    cin >> CardID;

    Findcard(CardID);



    if(books[i]->getBookID() == 0) {

    cout << "You do not have any books checked out" << endl;

    }else {

    if(books[i]->getstatus() == 1){

    books[i]->setstatus(0);

    cards[j]->setBookID(BookID);

    }

    }

    }

    }







    strauss.udel.edu% make

    CC -c library.cc

    "library.cc", line 28: Error: Expected an expression.

    "library.cc", line 62: Error: The operation "std::basic_ostream<char, std::char_traits<char>> >> const char*" is illegal.

    "library.cc", line 67: Error: input is not defined.

    "library.cc", line 67: Error: Badly formed expression.

    "library.cc", line 73: Error: The operation "std::basic_ostream<char, std::char_traits<char>> >> const char*" is illegal.

    5 Error(s) detected.

    *** Error code 5

    make: Fatal error: Command failed for target `library.o'

    strauss.udel.edu% exit

    strauss.udel.edu%
    script done on Tue Dec 04 17:01:59 2001

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    53
    Use the code tags (the # button above the bit where you type your post in) 'cause your code is pretty difficult to read otherwise...

    Almosthere
    "Technology has merely provided us with a more efficient means for going backwards" - Aldous Huxley

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    I need help with 5 error messages. I'm new at c++ so I don't understand what these errors mean or I don't see what I did wrong.


    Script started on Tue Dec 04 17:01:36 2001
    strauss.udel.edu% cat librar          cat library.h

    //header file for library class

    #ifndef Library_H
    #define Library_H
    #include "book.h"
    #include "card.h"
    #include <fstream.h>
    #include <iostream.h>



    class Library {
    private:
    char command;
    static int num_books;
    static int num_cards;
    Book *books[100];
    Card *cards[100];
    void printcards();
    void printbooks();
    void checkout();
    void checkin();
    public:
    Library(ifstream &input);
    ~Library();
    void DoCommand(char);
    Book* Findbook(int);
    Card* Findcard(int);
    static int getnum_books;
    static int getnum_cards;
    };
    #endif

    strauss.udel.edu% cat libraray  y.cc

    //member definition for library class

    #include "book.h"
    #include "card.h"
    #include "library.h"
    #include <string.h>
    #include <fstream.h>
    #include <iostream.h>

    Library :: Library(ifstream &input) {
    Book *book;
    Card *card;
    char title[100];
    char author[100];
    char name[100];
    char phone[100];
    int BookID;
    int BID;
    int CardID;
    int CID;
    int status;
    int i =0, j = 0;

    input.getline(title, 100);

    for(int i = 0; i < 100; i++) {
    books[i] = NULL;
    i = 0;
    while(strcmp(title, $$$) != 0) {
    input.getline(author, 100);
    input >> BookID >> status >> CID;
    books[i] = new Book(title, author, BookID, status, CID);
    num_books++;
    input.ignore();
    input.getline(title, 100);
    i++;
    }
    }

    input.getline(name, 100);

    for(int j = 0; j < 100; j++) {
    cards[j] = NULL;
    j = 0;
    while(!input.eof()) {
    input.getline(phone, 100);
    input >> CardID >> BID;
    cards[j] = new Card(name, phone, CardID, BID);
    num_cards++;
    input.ignore();
    input.getline(name, 100);
    j++;
    }
    }

    }

    Book* Library :: Findbook(int b) {
    int i = 0;

    while(books[i] != NULL) {
    if(books[i]->getBookID() == b)
    return books[i];
    else
    i++;
    }
    cout >> "Book not found";
    return NULL;
    }

    Card* Library :: Findcard(int c) {
    int j = 0;

    while(!input.eof()) {
    if(cards[j]->getCardID() == c)
    return cards[j];
    else
    j++;
    }
    cout >> "Card not found";
    return NULL;
    }

    void Library :: DoCommand(char c) {
    command = c;
    int i = 0, j = 0, BookID, CardID;

    if(command = 'B'){
    while(books[i] != NULL) {
    cout << "Processing book - ";
    books[i]->print() ;
    cout << endl;
    i++;
    }
    cout << num_books << "books in the library" << endl;
    }else if(command = 'C') {
    while(cards[j] != NULL) {
    cout << "Processing card - ";
    cards[j]->print();
    cout << endl;
    j++;
    }
    cout << num_cards << "cards in the library" << endl;
    }else if(command = 'O') {
    cout << "Enter book ID: ";
    cin >> BookID;
    Findcard(CardID);
    cout << "Enter card ID: ";
    cin >> CardID;
    Findbook(BookID);

    if(books[i]->getBookID() != 0) {
    cout << "Sorry. You can't check out a book until"
    << "you return the book that you checked out"
    << "before." << endl;
    }else {
    if(books[i]->getstatus() == 0) {
    books[i]->setstatus(1);
    cards[j]->setBookID(BookID);
    books[i]->setCardID(CardID);
    }else if(books[i]->getstatus() == 1) {
    cout << "Sorry, but the has already been"
    << "checked out."<< endl;
    }else {
    cout << "Book is at the bindery."<< endl;
    }
    }
    }else if(command = 'W') {
    cout << "Enter book ID: ";
    cin >> BookID;
    Findbook(BookID);
    cout << "Enter card ID: ";
    cin >> CardID;
    Findcard(CardID);

    if(books[i]->getBookID() == 0) {
    cout << "You do not have any books checked out" << endl;
    }else {
    if(books[i]->getstatus() == 1){
    books[i]->setstatus(0);
    cards[j]->setBookID(BookID);
    }
    }
    }
    }
    strauss.udel.edu% make

    CC -c library.cc

    "library.cc", line 28: Error: Expected an expression.

    "library.cc", line 62: Error: The operation "std::basic_ostream<char, std::char_traits<char>> >> const char*" is illegal.

    "library.cc", line 67: Error: input is not defined.

    "library.cc", line 67: Error: Badly formed expression.

    "library.cc", line 73: Error: The operation "std::basic_ostream<char, std::char_traits<char>> >> const char*" is illegal.

    5 Error(s) detected.

    *** Error code 5

    make: Fatal error: Command failed for target `library.o'

    strauss.udel.edu% exit

    strauss.udel.edu%
    script done on Tue Dec 04 17:01:59 2001

  4. #4
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    See the "cout" lines below.

    Book* Library :: Findbook(int b) {

    int i = 0;

    while(books[i] != NULL) {
    if(books[i]->getBookID() == b)
    return books[i];
    else
    i++;
    }
    cout >> "Book not found"; //Arrows pointing backwards
    return NULL;
    }

    Card* Library :: Findcard(int c) {
    int j = 0;
    while(!input.eof()) {
    if(cards[j]->getCardID() == c)
    return cards[j];
    else
    j++;
    }
    cout >> "Card not found"; //Arrows pointing backwards
    return NULL;
    }

  5. #5
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Also, maybe change this:
    Card* Library :: Findcard(int c) {

    to this:
    Card* Library :: Findcard(ifstream &input, int c) {

    And make the change where the class is defined:
    Card* Findcard(ifstream, int);

  6. #6
    Banned maes's Avatar
    Join Date
    Aug 2001
    Posts
    744

    question

    I'm currious, just a question but what do the $$$ mean in the strcmp function

    while(strcmp(title, $$$) != 0)

  7. #7
    Registered User
    Join Date
    Oct 2001
    Posts
    23
    The $$$ is when the the books data changes to cards data. I changed teh ">>" around and I changed Card* Findcard(int) to Card* Findcard(ifstream&, int) in the header file. I changed Card* Library::Findcard(int c) to Card* Library::Findcard(ifstream &input, int c). What should I put in the GoCommand function for Findcard(CardID)? What do I write for the argument of ifstream? This is the line 126 errors.

    "library.cc", line 28: Error: Expected an expression.

    "library.cc", line 99: Error: Formal argument input of type std::basic_ifstream<char, std::char_traits<char>>& in call to Library::Findcard(std::basic_ifstream<char, std::char_traits<char>>&, int) requires an lvalue.

    "library.cc", line 99: Error: Too few arguments in call to "Library::Findcard(std::basic_ifstream<char, std::char_traits<char>>&, int)".

    "library.cc", line 126: Error: Formal argument input of type std::basic_ifstream<char, std::char_traits<char>>& in call to Library::Findcard(std::basic_ifstream<char, std::char_traits<char>>&, int) requires an lvalue.

    "library.cc", line 126: Error: Too few arguments in call to "Library::Findcard(std::basic_ifstream<char, std::char_traits<char>>&, int)".

    5 Error(s) detected.

  8. #8
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Change this:
    void DoCommand(char);
    to this:
    void DoCommand(ifstream &,char);


    Change this:
    void Library :: DoCommand(char c) {
    to this:
    void Library :: DoCommand(ifstream &input, char c) {

    Then both:
    Findcard(CardID);
    to this:
    Findcard(input, CardID);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. getting to grips with allegro and ms vc++ (newbie)
    By jimjamjahaa in forum C++ Programming
    Replies: 4
    Last Post: 11-18-2005, 06:49 PM
  2. Newbie in problem with looping
    By nrain in forum C Programming
    Replies: 6
    Last Post: 11-05-2005, 11:53 AM
  3. Newbie Programmer
    By Extropian in forum C++ Programming
    Replies: 3
    Last Post: 05-18-2004, 01:17 PM
  4. Some help for a newbie?
    By Ilmater in forum C++ Programming
    Replies: 23
    Last Post: 04-19-2004, 07:44 PM
  5. Newbie Game Develpoers Unite!
    By Telenosis in forum Game Programming
    Replies: 10
    Last Post: 06-22-2002, 02:02 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21