int _tmain(int argc, _TCHAR* argv[])
{
int nTmp=-3;
char cTmp1= '0';
char cTmp2= '0';
char buf[]= "{5, ";
istringstream ist(buf);
ist >> cTmp1;
ist >> nTmp;
ist >> cTmp2;
return 0;
}
If compiled with VS2003 you get cTmp1= { nTmp= 5 cTmp2= ,
which is the desired result.
in VS2005 the nTmp value remains = -3. It appears that the >> operation can
not
handle an int, combination. int , is ok.
Is there a workaround that does not require the input data to be modifed?
Looks like the infamous locales problem. Try adding:
std::locale::global(std::locale::classic());
at the start of your program. I think the problem is that the program is
picking up ',' as a special character for ints, presumably the thousands
separator, due to not running in the "C" locale, but rather I think it
has picked up the Windows locale.
Tom
I'm afraid it's worse than that. It's a collision of two "under the radar"
changes
to the C++ Standard that have slowly become apparent through changes in
validation suites. The first is a requirement that the thousands separator
be
reported as comma *even in the "C" locale*, where it has long been "no
character". We put that in for V8 (Visual Studio 2005) and discovered
belatedly that the code now eats trailing commas. Turns out, however,
that another sub rosa change, in the handling of grouping, tells us not to
eat that comma; but that change didn't make it into V8. I believe this
issue popped up on this NG last December.
Bottom line: The fix is to change one line in _Getifld in <xlocnum> from:
const _Elem _Kseparator = _Punct_fac.thousands_sep();
to:
const _Elem _Kseparator = _Grouping.size() == 0
? (_Elem)0 : _Punct_fac.thousands_sep();
This defeats looking for separators if no grouping is specified.
The same fix is required in _Getmfld in <xlocmon>.
I believe Microsoft plans to patch this sooner rather than later, because
it's such a nuisance.
P.J. Plauger
Dinkumware, Ltd.
http://www.dinkumware.com
Thanks for the information on this.
For those of us who are a little slow, could you be explicit about exactly
what the second fix is. I looked for _Getmfld in <xlocmon> for Visual C++
Express 2005 and, while I found _Getmfld, I couldn't find it in any
expression that looks like the one that _Kseparator is in.
--
John Carson
Sorry, it is a bit messier. Look for the code sequence:
case money_base::value:
{ // parse value field
int _Fracdigseen = 0;
int _Fracdigits = _Ppunct_fac->frac_digits();
const _Elem _E0 = _MAKLOCCHR(_Elem, '0', _Cvt);
const string _Grouping = _Ppunct_fac->grouping();
if (CHAR_MAX <= (unsigned char)*_Grouping.c_str())
for (; _First != _Last
&& _E0 <= *_First && *_First <= _E0 + 9; ++_First)
_Val += *_First; // no grouping, just gather digits
else
{ // grouping specified, gather digits and group sizes
const _Elem _Kseparator = _Ppunct_fac->thousands_sep();
string _Groups((size_t)1, '\0');
size_t _Group = 0;
and change it to:
case money_base::value:
{ // parse value field
int _Fracdigseen = 0;
int _Fracdigits = _Ppunct_fac->frac_digits();
const _Elem _E0 = _MAKLOCCHR(_Elem, '0', _Cvt);
const string _Grouping = _Ppunct_fac->grouping();
const _Elem _Kseparator = _Grouping.size() == 0
? (_Elem)0 : _Ppunct_fac->thousands_sep();
if (_Kseparator == (_Elem)0
|| CHAR_MAX <= (unsigned char)*_Grouping.c_str())
for (; _First != _Last
&& _E0 <= *_First && *_First <= _E0 + 9; ++_First)
_Val += *_First; // no grouping, just gather digits
else
{ // grouping specified, gather digits and group sizes
string _Groups((size_t)1, '\0');
size_t _Group = 0;
HTH,
Will these be be posted on the Dinkumware web site, similar to the way
that VC6 library patches were?
Is there a proccedure for this?
Bill Fisher (schedman)
No. We don't want to trip over Microsoft's own support machinery.
When we put up the V6 patches, many years ago, things were rather
different.
> Thanks for the quick replies.
> I tried the std::locale::global(std::locale::classic());
> it did not work (as anticipated by P J Plauger). I have found the place to
> modify xlocmon but I have never patched microsoft code before. It seems I
> need to change some file protection to edit things, and I gues I need to
> recompile it.
>
schedman:
The best way to patch any of the include files that come with your VC
installation is to copy the offending files to a different folder, and
edit them there. Then put this folder above all the VC includes in your
VC Include directory settings (Tools, Options, Projects, VC++
Directories). That way, you can always go back by moving your new folder
to the bottom of the list.
David Wilkinson
Unfortunately I still get -3 for nTmp.
I looked at the code called by the >> and it appears that there is a step
in a file xlocnum (l602) that is dealing with _Ksepartor. but I can't follow
what is going on.
It does not appear that code in xlocmon.
any thoughts?
> P.J Plauger, all
> I gave the modification a try. I place the modified file Xlocmon in
> another
> folder and changed the order as David Wilkerson sugested. I can see that
> the
> modified h file is used by placing an #include <xlocmon> at the begining
> of
> the program and having VS show me the source code.
>
> Unfortunately I still get -3 for nTmp.
>
> I looked at the code called by the >> and it appears that there is a step
> in a file xlocnum (l602) that is dealing with _Ksepartor. but I can't
> follow
> what is going on.
> It does not appear that code in xlocmon.
>
> any thoughts?
Are you linking dynamically or statically. If the former, you have to
rebuild
the supplied DLL (not an easy chore).
"P.J. Plauger" wrote:
When I create dlls I generally use static dlls but in this case everything
I created is in main. There is only a few lines of code. I don't know how to
tell if the microsoft code is static. I looked at the VS2005 documentation
but that did not seem to answer your question. I accepted the MS VS2005
defaults for a Win32 Console client.
Bill Fisher (schedman)
>
>
With VS 2005, projects use the DLL version of the CRT (and the STL) by
default, so you're using the DLL version.
-cd
> Is it possible to override this behavior to test the change above, or is there a poceeddure for recompiling xlocmon.
Also has Microsoft set a date for when this issue might be patch?
Thanks
>
Go to
Project->Properties->Configuration Properties->C/C++ ->Code Generation
and make the appropriate selection in Runtime Library (you want /MT or /MTd
instead of /MD or /MDd).
--
John Carson
They've announced that there will be a service pack for VS 2005 in the first
1/2 of this year. If you want to increase the chances that this issue will
be addressed in the service pack, please go to
http://lab.msdn.microsoft.com/productfeedback
and report the bug. Bugs reported by customers through this mechanism are
far more likely to be fixed in a service pack. You should mention this
newsgroup thread in the bug report:
http://groups.google.com/group/microsoft.public.vc.language/browse_frm/thread/64ac882a37ddb1e9/eee6c084d09bf204is the Url for this thread from Google Groups.-cd
"Carl Daniel [VC++ MVP]" wrote:
-cd
"schedman" <sche...@discussions.microsoft.com> wrote in message
news:90663BD4-5108-485D...@microsoft.com...