1

I try to create a locale with following line of code:

std::locale loc(std::locale::classic(), new comma);

The definition of comma is:

struct comma : std::numpunct<char> {
    char do_decimal_point() const { return ','; }
};

I thought it should work as I saw a similar constructor call in the MSDN documentation to facet. Unfortunatelly I get the error:

error C2664: '__thiscall std::locale::std::locale(const char *,int)' : cannot convert parameter number 1 from 'const class std::locale' in 'const char *'

Do you know, how I can get it right?

There are a some answers on Stackoverflow, which do it right this way (this, or this one). But it seems, that the old VC6 compiler doesn't support this constructor (although the example in the VC6 documentation uses it). But there must be a way to use facets with VC6, otherwise it wouldn't be part of the documentation.

Community
  • 1
  • 1
Christian Ammer
  • 7,464
  • 6
  • 51
  • 108
  • You're being _very_ optimistic about VC6. I'm surprised there's still MSDN documentation, but it's certainly not supported anymore. I.e. if the documentation is wrong, Microsoft won't fix it. – MSalters Nov 21 '13 at 09:30
  • @MSalters: I'm optimistic about the people participating stackoverflow.com, more often then not I got a helpful answer, but unfortunatelly nobody has a pleasure to dig into VC6 parts. – Christian Ammer Nov 21 '13 at 10:19
  • 1
    Well, there are more people working to revive the dodo than people who'd like to see VC6 back. – MSalters Nov 21 '13 at 12:18

1 Answers1

1

To create a std::locale with a user defined facet we can use _ADDFAC. In the documentation to the locale constructor I found this helpful hint:

[...] you should write _ADDFAC(loc, Facet) to return a new locale that adds the facet Facet to the locale loc, since not all translators currently support the additional template constructors

VC6 doesn't seem to support the additional template constructors.

Sample Code:

std::istringstream iss("333,444"); // comma is decimal mark
std::locale loc(std::_ADDFAC(iss.getloc(), new comma));
iss.imbue(loc);
iss >> e;
std::cout << e << std::endl; // prints 333.444
Christian Ammer
  • 7,464
  • 6
  • 51
  • 108
  • The best source for that compiler still is the standalone MSDN install of 1998 or 1999 (that you can't install on win 7 64bits :( ).The edit on MSDN documentation in the years rewrite the past as VC6 works like the slow compilers that came after. Writing STL with VC6 is laborious because of many partial implementations. – ColdCat Dec 16 '13 at 08:59
  • You are right, VC6 on my machine runs on a virtual 32 bit XP environment. I need it for some old large projects, where it would be difficult to port them into a new IDE. The downside is, that I always have to be careful in using the STL with VC6. – Christian Ammer Dec 16 '13 at 09:11