I have the following program below:
#include <ctime>
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
// Function prototypes
unsigned int Stopwatch (const char *cmdline);
int main (short n_arg, char *arg[])
{
short err_level = 1;
if (n_arg < 2)
cout << "----------------------------------\n"
<< "Stpwatch Command - Version 1.1\n"
<< "Copyright (c) 2007 Samuel Louren‡o\n"
<< "----------------------------------\n"
<< "Stpwatch comes with ABSOLUTELY NO WARRANTY. This is free software and you are\n"
<< "welcome to distribute it under the terms of the GNU General Public License.\n"
<< "Open \"COPYING.TXT\" to read the license.\n\n"
<< "Usage: stpwatch command [command_arguments]" << endl;
else
{
string cmd_line = string (arg[1]);
for (int i = 2; i < n_arg; i ++)
{
cmd_line += " " + string (arg[i]);
}
cout << fixed << setprecision (3)
<< "Executing command...\n"
<< "===============================================================================" << endl;
int ticks = Stopwatch (cmd_line.c_str ());
cout << "\n===============================================================================\n"
<< "Elapsed time: " << ticks << " clock ticks\n"
<< " " << 1.0 * ticks / CLOCKS_PER_SEC << " seconds" << " (at " << CLOCKS_PER_SEC << " clock ticks per second)" << endl;
err_level = 0;
}
return err_level;
}
unsigned int Stopwatch (const char *cmd_line)
{
unsigned int initial_tm = clock ();
system (cmd_line);
return (clock () - initial_tm);
}
However, if I take off the include to <string> or to <ctime>, the program compiles as if <string> or <ctime> were sucessfully included, and also runs correctly. Of course this is wrong, how can a program be compiled if I didn't included the needed libraries? The program should emit errors.