having trouble with ifstream

This is a discussion on having trouble with ifstream within the C++ Programming forums, part of the General Programming Boards category; I need help with the error messages that I keep getting. I'm thinking that there's only one problem and they ...

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

    Unhappy having trouble with ifstream

    I need help with the error messages that I keep getting. I'm thinking that there's only one problem and they one problem caused the other problems. I think the one problem is with ifstream.

    Script started on Sun Dec 02 18:27:11 2001
    strauss.udel.edu% cat library.h

    //header file for library class



    #ifndef Library_H

    #define Library_H

    #include "book.h"

    #include "card.h"

    #include <fstream>



    class Library {

    private:

    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();

    DoCommand(char);

    Findbook(int);

    Findcard(int);

    static int getnum_books;

    static int getnum_cards;

    };



    #endif

    strauss.udel.edu% cat lir brary.cc

    //member definition for library class



    #include "book.h"

    #include "card.h"

    #include "library.h"

    #include <string>

    #include <iostream>



    using std :: cout;

    using std :: cout;



    Library :: Library(ifstream &input) {

    input.getline(title, 100, "\0");



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

    books[i] = NULL;

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

    input.getline(author, 100, "\0");

    input >> BookID >> status >> CardID;

    input.ignore();

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

    num_books++;

    input.getline(title, 100, "\0");

    }

    }

    input.getline(name, 100, "\0");



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

    cards[j] = NULL;

    while(!input.eof()) {

    input.getline(phone, 100, "\0");

    input >> CardID >> BookID;

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

    num_cards++;

    input.getline(name, 100, "\0");

    }

    }

    Library :: Findbook(Book b) {

    while(b[i] != NULL) {

    if(BookID == b.BookID)

    return BookID;

    else

    i++;

    }

    cout >> "Book not found";

    }

    Library :: Findcard(Card c) {

    while(c[i] != eof()) {

    if(CardID == c.CardID)

    return CardID;

    else

    j++;

    }

    cout >> "Card not found";

    }

    Library :: DoCommand(char c) {

    command = c;



    if(command = 'B'){

    while(books[i] != NULL) {

    cout << "Processing book - ";

    b[i]->print() ;

    cout << endl;

    i++;

    }

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

    }else if(command = 'C') {

    while(cards[j] != NULL)) {

    cout << "Processing card - ";

    c[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(getBookID() != 0) {

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

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

    << "before." << endl;

    }else {

    if(getstatus() == 0) {

    setstatus(1);

    setBookID(BookID);

    setCardID(CardID);

    }else if(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(getBookID() == 0) {

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

    }else {

    if(getstatus() == 1){

    setstatus(0);

    setBookID(BookID);

    }

    }

    }







    strauss.udel.edu% make

    CC -c library.cc

    "library.h", line 20: Error: ifstream is not defined.

    "library.cc", line 12: Error: ifstream is not defined.

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

    "library.cc", line 13: Error: title is not defined.

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

    "library.cc", line 17: Error: title is not defined.

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

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

    "library.cc", line 18: Error: author is not defined.

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

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

    "library.cc", line 19: Error: BookID is not defined.

    "library.cc", line 19: Error: status is not defined.

    "library.cc", line 19: Error: CardID is not defined.

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

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

    "library.cc", line 21: Error: title is not defined.

    "library.cc", line 21: Error: author is not defined.

    "library.cc", line 21: Error: BookID is not defined.

    "library.cc", line 21: Error: status is not defined.

    "library.cc", line 21: Error: CardID is not defined.

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

    "library.cc", line 23: Error: title is not defined.

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

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

    Compilation aborted, too many Error messages.

    *** Error code 1

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

    strauss.udel.edu% exit

    strauss.udel.edu%
    script done on Sun Dec 02 18:27:30 2001

  2. #2
    Registered User
    Join Date
    Nov 2001
    Posts
    65
    try adding
    using namespace std;
    to your Library.h file

    after
    #ifndef Library_H

    #define Library_H

    #include "book.h"

    #include "card.h"

    #include <fstream>

    using namespace std; <-----------

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. ifstream with getline?
    By DigiAcid in forum C++ Programming
    Replies: 13
    Last Post: 03-08-2009, 09:14 AM
  2. Simple ifstream Question
    By Paul22000 in forum C++ Programming
    Replies: 8
    Last Post: 12-05-2008, 05:34 PM
  3. ifstream
    By Wraithan in forum Tech Board
    Replies: 3
    Last Post: 09-24-2006, 02:26 AM
  4. ofstream and ifstream for searching and writing
    By johnnyd in forum C++ Programming
    Replies: 6
    Last Post: 03-17-2003, 08:34 AM
  5. Ifstream Problems
    By IlUomo in forum Windows Programming
    Replies: 1
    Last Post: 04-24-2002, 01:51 PM

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