BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

std::time_put<char >::put() gives me bad date

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Command Line Tools)
View previous topic :: View next topic  
Author Message
Gary Setter
Guest





PostPosted: Tue May 24, 2005 1:18 pm    Post subject: std::time_put<char >::put() gives me bad date Reply with quote



Hi,

I'm trying to modify one of my programs to work with BCB5.5. The function
that creates a string with the current date is failing. I was using the
standard template library, Rogue Wave which came with the compiler. As an
experiment I tried the c runtime function strftime(), The strftime()
function worked.
This is the results, strftime() first, std::time_put<char >::put() second:
local date 05/24/05 date and time 05/24/05 07:56:33
local date 11/30/90 date and time 11/30/90 22:54:56

Most likely, I would just use strftime(). But I have to ask, am I using
std::time_put<char >::put() improperly? Could my code be improved?

Also, when macro _RWSTD_COMPILE_INSTANTIATE is defined, the put function is
defined in includerwtime.cc. However where is that function defined when
the above macro is not defined? I'm stumped. Does anyone here have an
answer?

The source follows.
Thanks,
Gary

#include <iostream>
#include <time.h>
#include <locale>
#include <sstream>

typedef std::time_put<char,std::ostreambuf_iterator timput;

const char *fmt ="local date %x date and time %c";

int main(int , char* )
{
time_t timer;
time(&timer);

tm *localTime = localtime(&timer);
{
char buf[80];
int cnt = strftime(buf,sizeof(buf),fmt,localTime);
if (cnt > 0)
std::cout << buf << 'n';
}
std::ostringstream os;
std::locale loc;
os.imbue(loc);
std::ostreambuf_iterator const timput & tp =
std::use_facet<timput >(loc);
tp.put(it,os,' ',localTime,fmt,fmt + strlen(fmt));
std::cout
<< os.str().c_str()
<< 'n';
return 0;
}

Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder (Command Line Tools) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.