Hi All:
I have downloaded C++ 2005 Express from Microsoft.
I then run a date + time program, the compiler says the
functions I am using are deprecated, and I should use
localtime_s.
So You go to Microsoft, search for localtime_s.
You throw the example code into your compiler.
Bingo FORD, Found on Road Dead.
It won't compile.
Why, they are using the exit function
and forgot to include <stdlib.h>.
I DON'T think it will work!
How they got it to work without this library is
totally amazing and also impossible.
If you are totalled bored and have nothing to
do. Go to Microsoft and search for localtime_s.
Read the entry Hi All.
or read the Microsoft entry for localtime_s.
http://msdn2.microsoft.com/en-us/library/a442x3ye.aspx
Microsoft help
http://support.microsoft.com/contactus/?ws=support
Code Sample that will work!
// REM LOCALTIME.CPP 7:29 AM 8/22/2006
/// / Source From http://msdn2.microsoft.com// /en-us/library/a442x3ye.aspx
// crt_loca// ltime_s.c// _getch ( ) added 8:56 PM 8/30/2006
/* this program uses _time64 to get the current time * and then uses _localtime64_s() to convert this time to a structure * representing the local time. */
#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h> // MUST HAVE for exit to work??
#include <conio.h> // for _getch( )
int main( void )
{
struct tm newtime;
char am_pm [ ] = "AM";
__time64_t long_time;
char timebuf[26];
errno_t err;
// Get time as 64-bit integer.
_time64 ( &long_time );
// Convert to local time.
err = _localtime64_s ( &newtime, &long_time );
if ( err )
{ printf( "Invalid argument to _localtime64_s." );
exit ( 1 ); }
if ( newtime.tm_hour > 12 )
// Set up extension.
strcpy_s ( am_pm, sizeof ( am_pm ), "PM" );
if ( newtime.tm_hour > 12 )
// Convert from 24-hour
newtime.tm_hour -= 12;// to 12-hour clock.
if ( newtime.tm_hour == 0 )
// Set hour to 12 if midnight.
newtime.tm_hour = 12; // Convert to an ASCII representation.
err = asctime_s ( timebuf, 26, &newtime );
if ( err ) { printf ( "Invalid argument to asctime_s." );
exit ( 1 ); }
printf ( "%.19s %s\n", timebuf, am_pm );
_getch(); // Pause, Wait for Keyboard
}
// Sample Output
// Fri Apr 25 01:19:27
// PM // F:\PROGRA~1\MID05A~1\VC\bin>cl
// altime
// Microsoft (R) 32-bit C/C++ Optimizing
// Compiler Version 14.00.50727.42 for 80x8
// 6
// Copyright (C) Microsoft Corporation.
// All rights reserved.
// cl : Command line warning D9024 : unr
// ecognized source file type 'localtime',
// obj
// ect file assumed
// Microsoft (R) Incremental Linker Vers
// ion 8.00.50727.42
// Copyright (C) Microsoft Corporation
// All rights reserved.
// /out:localtime.exe
// localtime
// F:\PROGRA~1\MID05A~1\VC\bin>localt
// ime
// Wed Aug 30 09:00:34 PM
// F:\PROGRA~1\MID05A~1\VC\bin>snap
//
I even complained to Microsoft back in June 5, 2006.
So it's taken over a hundred days to insert one line
of code. Which they have not done yet.
#include <stdlib.h>
Do you know of any reliable sites about C++ 2005,
Microsoft does not have reliable documentation.
I usually find that after reading a help document you
actually know less about it after reading it!
These guys are good?
The original complaint:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=450901&SiteID=1
Enjoy!
Yours Truly: Herge