Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

istringstream not working the same in Visual Studio 2005

15 views
Skip to first unread message

schedman

unread,
Jan 24, 2006, 12:37:02 AM1/24/06
to
In moving some code from VS2003 to VS2005 I have an execution error which I
traced to the following example code (Win 32 Console app)
#include "stdafx.h"
#include <sstream>
using namespace std;

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?

Tom Widmer [VC++ MVP]

unread,
Jan 24, 2006, 4:56:01 AM1/24/06
to

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

P.J. Plauger

unread,
Jan 24, 2006, 7:02:26 AM1/24/06
to
"Tom Widmer [VC++ MVP]" <tom_u...@hotmail.com> wrote in message
news:%23cs%23ixMI...@TK2MSFTNGP10.phx.gbl...

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


John Carson

unread,
Jan 24, 2006, 8:41:50 AM1/24/06
to
"P.J. Plauger" <p...@dinkumware.com> wrote in message
news:GtKdnY9qCfH...@giganews.com

>
> 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>.


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


P.J. Plauger

unread,
Jan 24, 2006, 9:17:27 AM1/24/06
to
"John Carson" <jcarson_n...@netspace.net.au> wrote in message
news:u7ZrrwOI...@TK2MSFTNGP09.phx.gbl...

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,

red floyd

unread,
Jan 24, 2006, 11:06:13 AM1/24/06
to
P.J. Plauger wrote:
> [patch descriptions redacted]

>
> P.J. Plauger
> Dinkumware, Ltd.
> http://www.dinkumware.com

Will these be be posted on the Dinkumware web site, similar to the way
that VC6 library patches were?

schedman

unread,
Jan 24, 2006, 11:56:03 AM1/24/06
to
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.

Is there a proccedure for this?

Bill Fisher (schedman)

P.J. Plauger

unread,
Jan 24, 2006, 1:14:32 PM1/24/06
to
"red floyd" <no....@here.dude> wrote in message
news:OU3SaAQ...@TK2MSFTNGP10.phx.gbl...

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.

David Wilkinson

unread,
Jan 24, 2006, 1:27:46 PM1/24/06
to
schedman wrote:

> 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

schedman

unread,
Jan 24, 2006, 2:51:31 PM1/24/06
to
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?

P.J. Plauger

unread,
Jan 24, 2006, 5:46:30 PM1/24/06
to
"schedman" <sche...@discussions.microsoft.com> wrote in message
news:684159AE-443C-4BAA...@microsoft.com...

> 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).

schedman

unread,
Jan 24, 2006, 6:06:14 PM1/24/06
to

"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)
>
>

Carl Daniel [VC++ MVP]

unread,
Jan 24, 2006, 10:18:08 PM1/24/06
to

With VS 2005, projects use the DLL version of the CRT (and the STL) by
default, so you're using the DLL version.

-cd


schedman

unread,
Jan 24, 2006, 11:32:02 PM1/24/06
to

> 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
>

John Carson

unread,
Jan 24, 2006, 11:59:33 PM1/24/06
to
"schedman" <sche...@discussions.microsoft.com> wrote in message
news:4DAC2EC9-6950-4FB8...@microsoft.com

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


Carl Daniel [VC++ MVP]

unread,
Jan 25, 2006, 10:05:13 AM1/25/06
to
schedman wrote:
> Also has Microsoft set a date for when this issue might be patch?

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

schedman

unread,
Jan 25, 2006, 12:00:03 PM1/25/06
to
Hello all
Thanks for your help,
My settings were /MTd, still didn't do it. I am going to use up one of my
MSDN incidents to work this.
I will post when(if) I have a solution.

"Carl Daniel [VC++ MVP]" wrote:

schedman

unread,
Jan 27, 2006, 11:39:04 AM1/27/06
to
An update. The MS product team has decided this is a bug with no workaround.
They a considering oit for a Quick Fix Engineering. Don't know what the
chances are; At least it is on the radar.

schedman

unread,
Apr 10, 2006, 12:06:02 PM4/10/06
to
I have a resolution of this problem in the form of a Hot fix from Microsoft.
I am not sure what the proceedure is for getting a copy of the hot fix but
the relavant Knowledge base article is KB911884.
Schedman

Carl Daniel [VC++ MVP]

unread,
Apr 10, 2006, 2:30:43 PM4/10/06
to
There's no such KB article. Are you sure you copied it correctly?

-cd

"schedman" <sche...@discussions.microsoft.com> wrote in message

news:90663BD4-5108-485D...@microsoft.com...

0 new messages