| | |
localtime_s, C++ 2005 Express
Please support our C++ advertiser: Programming Forums - DaniWeb Sister Site
| View Poll Results: Was this Localtime_s sample helpful? | |||
| Yes | | 2 | 66.67% |
| No | | 1 | 33.33% |
| Multiple Choice Poll. Voters: 3. You may not vote on this poll | |||
![]() |
•
•
Join Date: Jul 2006
Posts: 9
Reputation:
Solved Threads: 1
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!
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.
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/Sho...50901&SiteID=1
Enjoy!
Yours Truly: Herge
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!
C++ Syntax (Toggle Plain Text)
// REM LOCALTIME.CPP 7:29 AM 8/22/2006 /// / Source From <a rel="nofollow" class="t" href="http://msdn2.microsoft.com/" target="_blank">http://msdn2.microsoft.com</a>// /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 //
So it's taken over a hundred days to insert one line
of code. Which they have not done yet.
C++ Syntax (Toggle Plain Text)
#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/Sho...50901&SiteID=1
Enjoy!
Yours Truly: Herge
Last edited by WolfPack; Sep 20th, 2006 at 7:09 pm. Reason: removed unneccasary colors, added code tags
Yours Truly Herge:
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
Its true most sites have bad examples, and Microsoft is no exception. Your best bet if you are just learning is to study good and reliable text books. Microsoft documentation has greatly improved over the past 10 or so years. Some examples are still questionable, but they have cleaned up their act and most function descriptions are now accurate.
BTW: I always include pragma to remove those warnings about deprecated functions because it is only Microsoft, not c++ standards committee who made them like that. The functions they suggest with "_s" are Microsoft specific and will probably not compile with any other compiler. So I think you are better off not using them.
BTW: I always include pragma to remove those warnings about deprecated functions because it is only Microsoft, not c++ standards committee who made them like that. The functions they suggest with "_s" are Microsoft specific and will probably not compile with any other compiler. So I think you are better off not using them.
C++ Syntax (Toggle Plain Text)
#pragma warning(disable: 4996)
Last edited by Ancient Dragon; Sep 20th, 2006 at 6:02 pm.
•
•
•
•
Your best bet if you are just learning is to study good and reliable text books.
Another you could try is (my actual textbook for class) Absolute C++ by Walter Savitch (second edition). It might leave out examples and explanations of spaghetti-code, but you shouldn't use that anyway. It has much to go from, and plenty of example codes (that actually work).
•
•
Join Date: Jul 2006
Posts: 9
Reputation:
Solved Threads: 1
•
•
•
•
In my experience, you could start out with a C++ For Dummies, they are actually quite helpful.
Another you could try is (my actual textbook for class) Absolute C++ by Walter Savitch (second edition). It might leave out examples and explanations of spaghetti-code, but you shouldn't use that anyway. It has much to go from, and plenty of example codes (that actually work).
The C++ Programming Language,
by Bjarne Stroustrap,
AT & T Labs
Murray Hill, New Jersey
Published by Addison-Wesley, Pearson Education
Copyright 1997, AT & T
ISBN 0-201-700732-5
Over 1020 pages
There's nothing like getting it from the horses's mouth.
BJ created C++.
I brought this box in 2002, at that time it was slighty over
Hundred dollars Canadain.
Book says it sold for $ 64.99 in USA. I suspect it's
gone up since then.
I think he has retired from AT & T and gone down to
work at some College or University in Texas.
Yours Truly Herge:
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
•
•
Join Date: Jul 2006
Posts: 9
Reputation:
Solved Threads: 1
•
•
•
•
I personally would also try:
The C++ Programming Language,
by Bjarne Stroustrap,
AT & T Labs
Murray Hill, New Jersey
Published by Addison-Wesley, Pearson Education
Copyright 1997, AT & T
ISBN 0-201-700732-5
Over 1020 pages
There's nothing like getting it from the horses's mouth.
BJ created C++.
I brought this box in 2002, at that time it was slighty over
Hundred dollars Canadain.
Book says it sold for $ 64.99 in USA. I suspect it's
gone up since then.
I think he has retired from AT & T and gone down to
work at some College or University in Texas.
Yours Truly Herge:
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
•
•
Join Date: Jul 2006
Posts: 9
Reputation:
Solved Threads: 1
The Fact that Microsoft doesn't know that the C exit function needs
the <stdlib.h> is a cause of great concern. Most C or C++ compilers
need STDLIB.H file for the exit function to work. Even Micosoft C compilers need it.
I suspect this example is one of Millions of examples of bad code
from Microsoft. This is a very simple example they have screwed up
right royally.
It has taken over a hundred days and far as I know has not
been sorted out yet!
I would hate to ask what kind oF OS[Operating System] or name
of Text editor[Edlin,QED,Notepad, or god forbid Word.
I would hate to calculate Lines of code per Month that work.
The answer is always going to be zero.
If I told my manager I produced zero lines of code he would
fire me almost immediatelly, they seem to promote them
at Microsoft for this.
the <stdlib.h> is a cause of great concern. Most C or C++ compilers
need STDLIB.H file for the exit function to work. Even Micosoft C compilers need it.
I suspect this example is one of Millions of examples of bad code
from Microsoft. This is a very simple example they have screwed up
right royally.
It has taken over a hundred days and far as I know has not
been sorted out yet!
I would hate to ask what kind oF OS[Operating System] or name
of Text editor[Edlin,QED,Notepad, or god forbid Word.
I would hate to calculate Lines of code per Month that work.
The answer is always going to be zero.
If I told my manager I produced zero lines of code he would
fire me almost immediatelly, they seem to promote them
at Microsoft for this.
Yours Truly Herge:
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
// Belgian Cartoonist of Tintin and Snowy
// aka Georges Remi, born Brussels, Belgium
// May 22, 1907 – March 3, 1983
Okay. So microsoft hasn't compiled that code before submitting. Now what about whether it serves as a good example for
Everybody accepts the fact that the Microsoft examples ( or early compilers for that matter) are not standard compliant. Some examples start using the
I think you have succesfully brought the mistake in the example to our attention. You have taken it up to Microsoft and they will hopefully correct it in the future. That is the least you can do. Now it is time you quit overdoing things.
_localtime64_s? That is it's main objective isn't it? Once a programmer tries out the example and finds that exit() isn't defined, he will add the stdlib line and get it to compile. That is not much of an issue. It would have been a different matter if the example showed a wrong way of using the _localtime64_s function.Everybody accepts the fact that the Microsoft examples ( or early compilers for that matter) are not standard compliant. Some examples start using the
void main () function. But somehow a large number of programmers have managed to learn through those examples and continue to do so. For you it maybe just one example that needs one line to be added. But what about those all void main lines that need to be changed to int main? Maybe those examples came from the days before the standard made it mandatory for main to return an int. So while we understand that it is wrong, we are also fedup of hearing how MS suck from time to time. I think you have succesfully brought the mistake in the example to our attention. You have taken it up to Microsoft and they will hopefully correct it in the future. That is the least you can do. Now it is time you quit overdoing things.
Last edited by WolfPack; Sep 25th, 2006 at 6:43 am.
バルサミコ酢やっぱいらへんで
![]() |
Similar Threads
- sql server 2005 express i need help<<<? (MS SQL)
- Visual C++ 2005 Express Edition (C++)
- Visual C++ 2005 Express Edition (C++)
- Sub Forms using VB 2005 Express Edition (VB.NET)
Other Threads in the C++ Forum
- Previous Thread: can't figure out how to loop
- Next Thread: API Help
Views: 6506 | Replies: 7
| Thread Tools | Search this Thread |
Tag cloud for C++
6 api application array arrays assignment beginner binary bitmap c++ c/c++ calculator char char* class classes code coding compile compiler console conversion convert count data database delete developer display dll email encryption error file forms fstream function functions game generator getline givemetehcodez graph iamthwee ifstream image input int java lazy lib loop looping loops map math matrix memory multidimensional multiple newbie news node number numbertoword output pointer problem program programming project proxy python random read recursion recursive reference return sort sorting string strings struct template templates text tree url variable vector video visual visualstudio win32 windows winsock word wordfrequency wxwidgets






