Saturday, January 7, 2017

Discovery compiling a C++ program from a 2003 book

In listing B3.1 on page 666 of "Sam's Teaching Yourself C in 24 hours", Change

#include <iostream.h> to #include <iostream>

Add the line

using namespace std;

See: http://stackoverflow.com/questions/13103108/why-cant-g-find-iostream-h

compile using

g++ endtime.cpp -o endtime.o

or

g++ endtime.cpp

Using gcc instead of g++ you have: endtime.cpp: In function ‘int main(int, char**)’: endtime.cpp:24:3: error: expected ‘;’ before ‘end_time’ end_time.minutes = 11; ^ endtime.cpp: In function ‘void print_time(time)’: endtime.cpp:39:48: error: expected ‘;’ before ‘tm’ cout << tm.hours << ":" << tm.minutes << ":" tm.seconds; See: http://stackoverflow.com/questions/28236870/undefined-reference-to-stdcout

This post also took advantage of escape sequences for the less than and greater than symbols. http://www.theukwebdesigncompany.com/articles/entity-escape-characters.php

No comments:

Post a Comment