March 28th, 2013, 11:07 AM
compliing errors with timestamp code
I've written a simple program that output's my name, course, and a time \ date stamp.
Having researched the code to do so, I've used the includes for both the ctime and time.h libraries.
I leveraged localtime_s and asctime_s to actually convert to string etc., and the program runs fine when I step through it in Visual Studio.
However, we're working with CGI and this program will ultimately be called up from the cgi-bin directory of a web server. The first thing
that needs to be done after copying it to the webserver is to compile it. That's where my problem occurs.
Using the console command: g++ lab5a.cpp -o lab5a.exe the file is supposed to compile and be converted to a .exe.
However, instead I receive errors:
localtime_s was not declared in this scope
asctime_s was not declared in this scope
I "believe" it's because of the included libraries, but not sure.
Here's the actual timestamp block of code:
Of course, I go on to error check and complete the block, but you get the picture.
//Begin date and time instructions
struct tm locTime;
const int TimeStrLen = 26;
char timeStr[ TimeStrLen ];
if ( ( -1 != time( &curTime ) ) // Seconds since 01-01-1970
&& ( 0 == localtime_s( &locTime, &curTime ) ) // Convert to local time
&& ( 0 == asctime_s( timeStr, TimeStrLen, &locTime ) ) // Convert to string
Can somebody shed light on the errors and what might stop this code from compiling.
All that I've read points to deprecated code, specifically in the _s lines.
Click Here to Expand Forum to Full Width
This a Codeguru.com survey!