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.
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/cstdi o:44:0,
from /usr/include/c++/4.7/fstre am:43,
from book_collection.cpp:11:
/usr/include/stdio.h:675:2 0: note: __ssize_t getline(char**, size_t*, FILE*)
/usr/include/stdio.h:675:2 0: note: candidate expects 3 arguments, 2 provided
In file included from /usr/include/c++/4.7/strin g:54:0,
from /usr/include/c++/4.7/bits/ locale_cla sses.h:42,
from /usr/include/c++/4.7/bits/ ios_base.h :43,
from /usr/include/c++/4.7/ios:4 3,
from /usr/include/c++/4.7/ostre am:40,
from /usr/include/c++/4.7/iostr eam:40,
from book_collection.cpp:8:
#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)
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
book_collection.cpp:173:22
book_collection.cpp:173:22
In file included from /usr/include/c++/4.7/cstdi
from /usr/include/c++/4.7/fstre
from book_collection.cpp:11:
/usr/include/stdio.h:675:2
/usr/include/stdio.h:675:2
In file included from /usr/include/c++/4.7/strin
from /usr/include/c++/4.7/bits/
from /usr/include/c++/4.7/bits/
from /usr/include/c++/4.7/ios:4
from /usr/include/c++/4.7/ostre
from /usr/include/c++/4.7/iostr
from book_collection.cpp:8:
What is the code on line 173 of book_collection.cpp, and what is it trying to do?
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; //
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That was the problem. Thanks!