Archived

This topic is now archived and is closed to further replies.

Houdini

Internalization, locales, and dates

Recommended Posts

I'm having trouble trying to print out the date using locales. Here's my code:
    
#include <iostream>
#include <time.h>
#include <locale>
#include <time.h>

using namespace std;

int main()
{
	tm *cur_time;
	time_t long_time;

	time(&long_time);
	cur_time = localtime(&long_time);

	//cout.imbue(locale("English"));

	use_facet<time_put<char> >(cout.getloc()).put(cout, cout, cout.fill(), cur_time, 'c', '#');

	cout << endl;

	return 0;
}
    
Running this program prints nothing to the screen for me. Notice the 'c' and '#' format specifications on the third to last line? This is supposed to specifcy to print out a long date representation. If I take out the '#' completely, the short date version prints out fine (the '#' specifies I want the long date verison). However, if I put the '#' back in and I uncomment the //cout.imbue(locale("English")); line, then the long date prints out fine too! Any ideas on why I'm forced to manually set the locale for cout just to be able to print out the long date verision? - Houdini Edited by - Houdini on February 17, 2002 5:08:51 PM

Share this post


Link to post
Share on other sites
Ah, thanks for the heads up Oluseyi, I changed the header! However, it didn''t fix my problem.

But , doing so did give me the idea of trying a different STL implementation, so I recompiled with VC7''s STL instead of STLPort 4.5.3. It worked like a charm!

Looks like there''s a small bug in the latest STLPort release.


- Houdini

Share this post


Link to post
Share on other sites