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;


compile using

g++ endtime.cpp -o endtime.o


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:

This post also took advantage of escape sequences for the less than and greater than symbols.

No comments:

Post a Comment