D
daniele
Why the following code doesn't work? It prints the date using the
default locale instead of mine.
(compiled with Visual C++ 2008)
Thanks.
Daniele
#include <iostream>
#include <sstream>
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace boost:osix_time;
class Log
{
public:
Log();
void Get();
private:
static time_facet* myFacet;
static std::locale myLocale;
std:stringstream os;
};
time_facet* Log::myFacet( new time_facet( "%Y.%m.%d" ) );
std::locale Log::myLocale( std::locale(), myFacet );
Log::Log()
{
#if 0 // this works
time_facet* myfacet( new time_facet( "%Y.%m.%d" ) );
std::locale myLoc( std::locale(), myfacet );
os.imbue( myLoc );
#else // this doesn't work!!!
os.imbue( myLocale );
#endif
}
void Log::Get()
{
ptime t( second_clock::local_time() );
os << t << std::endl;
fprintf( stderr, "%s", os.str().c_str() );
fflush( stderr );
}
int main( int argc, char* argv[] )
{
Log l;
l.Get();
return 0;
}
default locale instead of mine.
(compiled with Visual C++ 2008)
Thanks.
Daniele
#include <iostream>
#include <sstream>
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace boost:osix_time;
class Log
{
public:
Log();
void Get();
private:
static time_facet* myFacet;
static std::locale myLocale;
std:stringstream os;
};
time_facet* Log::myFacet( new time_facet( "%Y.%m.%d" ) );
std::locale Log::myLocale( std::locale(), myFacet );
Log::Log()
{
#if 0 // this works
time_facet* myfacet( new time_facet( "%Y.%m.%d" ) );
std::locale myLoc( std::locale(), myfacet );
os.imbue( myLoc );
#else // this doesn't work!!!
os.imbue( myLocale );
#endif
}
void Log::Get()
{
ptime t( second_clock::local_time() );
os << t << std::endl;
fprintf( stderr, "%s", os.str().c_str() );
fflush( stderr );
}
int main( int argc, char* argv[] )
{
Log l;
l.Get();
return 0;
}