Link to home
Start Free TrialLog in
Avatar of jdubya103
jdubya103

asked on

C++ compile errors with g++ compiler

I think maybe one of my .cpp files is not getting linked.  Makefiles are new to me but I think this one is correct.

#Use the g++ compiler
CC = g++

# Compiler flags:
#   -Wall (most warnings enabled)
#   -g (for debugging with gdb)
CFLAGS = -Wall

# Executable name:
TARGET = book_collection

all: main.o book_collection.o book_database

$(TARGET): main.o book_collection.o
	$(CC) $(CFLAGS) main.o book_collection.o -o $(TARGET)

main.o: main.cpp book_collection.h
	$(CC) $(CFLAGS) main.cpp -c

dvd_collection.o: book_collection.cpp book_collection.h
	$(CC)  $(CFLAGS) book_collection.cpp -c

clean:
	rm *.o *~ $(TARGET)

Open in new window



There is no .o file for the collection.cpp showing when I run an ls command. Here is the ls:

     book_collection.cpp  book.h    main.o    Makefile~
     book_collection.h    main.cpp  Makefile  user_collection.txt

 
Here is a small portion of the error messages I'm getting.  

g++    -c -o book_collection.o book_collection.cpp
book_collection.cpp: In member function ‘void book_collection::read_from_file(std::string)’:
book_collection.cpp:173:22: error: no matching function for call to ‘getline(std::ifstream&, int&)’
book_collection.cpp:173:22: note: candidates are:
In file included from /usr/include/c++/4.7/cstdio:44:0,
                 from /usr/include/c++/4.7/fstream:43,
                 from book_collection.cpp:11:
/usr/include/stdio.h:675:20: note: __ssize_t getline(char**, size_t*, FILE*)
/usr/include/stdio.h:675:20: note:   candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/4.7/string:54:0,
                 from /usr/include/c++/4.7/bits/locale_classes.h:42,
                 from /usr/include/c++/4.7/bits/ios_base.h:43,
                 from /usr/include/c++/4.7/ios:43,
                 from /usr/include/c++/4.7/ostream:40,
                 from /usr/include/c++/4.7/iostream:40,
                 from book_collection.cpp:8:
Avatar of ozo
ozo
Flag of United States of America image

What is the code on line 173 of book_collection.cpp, and what is it trying to do?
Avatar of jdubya103
jdubya103

ASKER

It reads file input.  I had this code working pretty well with dvd data a few weeks ago.  I tried to convert it to a book database today.  

void book_collection::read_from_file(std::string file_name)
{
  ifstream fin;
  string item, btitle, bauth;  // book title, book author
  int bpage, bisbn, byear;  // book pages, book isbn#, book copyright year
  double bprice;  // book price
  
  //file_name = "user_collection.txt";
  fin.open(file_name.c_str());

    fin >> item; // to skip book num  -- the file contains book1 <space> at first of line
  getline (fin, btitle); 
  
  fin >> item; // to skip book num
  getline (fin, bauth);
  
  fin >> item; // to skip book num
  getline (fin, bpage);    ///////  Line173

  fin >> item; //
  getline (fin, bisbn);

  fin >> item; //
  getline (fin, bprice);

  fin >> item; //

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of sarabande
sarabande
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That was the problem.  Thanks!