473,385 Members | 1,912 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

unexpected stream output with commas

Got a strange bug going on here...

// proper includes and additional code here
int x = 2552123;
cout << x;

This results in output like this: 2,552,123
Same behavior with stringstreams.

How can this be happening?
This doesn't always happen... seems like only when we create our executable
with some of our shared libraries (.so).
It works correctly when in main() but not when in our class source files.
When linking with static libraries (.a) it works as expected.

We are developing on AIX with Visual Age 6.0 if that matters.

It's probably something we are doing incorrectly with our shared
libraries... any hints as to what could be causing this?

Thanks,
Kyle
Jul 23 '05 #1
10 1702

"Kyle Kolander" <kk*******@hotmail.com> wrote in message
news:JZ***********@dfw-service2.ext.ray.com...
Got a strange bug going on here...

// proper includes and additional code here
int x = 2552123;
cout << x;

This results in output like this: 2,552,123
I take it you don't want the commas? Or do you want periods there? (You
don't specify what it is you actually expected.)
Same behavior with stringstreams.

How can this be happening?
This doesn't always happen... seems like only when we create our
executable
with some of our shared libraries (.so).
It works correctly when in main() but not when in our class source files.
When linking with static libraries (.a) it works as expected.

We are developing on AIX with Visual Age 6.0 if that matters.

It's probably something we are doing incorrectly with our shared
libraries... any hints as to what could be causing this?

Thanks,
Kyle

I'd guess that the shared libraries are specifying locale information, and
that includes whether or not to use thousands separators (and what to use
for them). Check the shared library code (and the settings used to build
them, perhaps?), and see if they're making such specifications. If not,
then perhaps you need to add code to tell them to NOT use the separators?
I'm not familiar with how to do such things, but this should help point you
in the right direction, at least. A Google search might help more.

-Howard


Jul 23 '05 #2
Kyle Kolander wrote:
Got a strange bug going on here...

// proper includes and additional code here
int x = 2552123;
cout << x;

This results in output like this: 2,552,123
Same behavior with stringstreams.

How can this be happening?
This doesn't always happen... seems like only when we create our executable
with some of our shared libraries (.so).
It works correctly when in main() but not when in our class source files.
When linking with static libraries (.a) it works as expected.

We are developing on AIX with Visual Age 6.0 if that matters.

It's probably something we are doing incorrectly with our shared
libraries... any hints as to what could be causing this?


Default locale setting uses 'do_grouping' that causes 'thousands_sep'
character to be inserted into the output. I don't know much about those
things, but read about locales in general. Could it be your code uses
different locales if a certain .so is loaded. It must set the locale
to something instead of just leaving it unchanged. Read the documentation
for that library, especially the part where it describes locales.

V
Jul 23 '05 #3
"Victor Bazarov" <v.********@comAcast.net> wrote in message
news:W4*******************@newsread1.mlpsca01.us.t o.verio.net...
Kyle Kolander wrote:
Got a strange bug going on here...

// proper includes and additional code here
int x = 2552123;
cout << x;

This results in output like this: 2,552,123
Same behavior with stringstreams.

How can this be happening?
This doesn't always happen... seems like only when we create our executable with some of our shared libraries (.so).
It works correctly when in main() but not when in our class source files. When linking with static libraries (.a) it works as expected.

We are developing on AIX with Visual Age 6.0 if that matters.

It's probably something we are doing incorrectly with our shared
libraries... any hints as to what could be causing this?


Default locale setting uses 'do_grouping' that causes 'thousands_sep'
character to be inserted into the output. I don't know much about those
things, but read about locales in general. Could it be your code uses
different locales if a certain .so is loaded. It must set the locale
to something instead of just leaving it unchanged. Read the documentation
for that library, especially the part where it describes locales.

V


Thanks guys... I started suspecting locale was the problem after a quick
search of google.
I have also only read a bit about locale settings and never used them.
I'll look into your suggestions.

Thanks again,
Kyle
Jul 23 '05 #4
Default locale setting uses 'do_grouping' that causes 'thousands_sep'
character to be inserted into the output. I don't know much about those
things, but read about locales in general. Could it be your code uses
different locales if a certain .so is loaded.


I guess we don't understand how the locale could vary based on whether
we use a .so or .a library, because the .a version works and the .so does
not.
Could you please shed a bit more light on this?

Thanks in advance,
Kyle

Jul 23 '05 #5
Kyle Kolander wrote:
Default locale setting uses 'do_grouping' that causes 'thousands_sep'
character to be inserted into the output. I don't know much about those
things, but read about locales in general. Could it be your code uses
different locales if a certain .so is loaded.

I guess we don't understand how the locale could vary based on whether
we use a .so or .a library, because the .a version works and the .so does
not.
Could you please shed a bit more light on this?


I could if I knew the details. My _guess_ would be that there is some
kind of initialisation code that .so executes when loaded, which might
contain setting the locale. You'll need to ask in a newsgroup where .so
and .a are topical, like a newsgroup for your OS.

I would also strongly recommend contacting the compiler vendor (IBM?).

V
Jul 23 '05 #6

"Kyle Kolander" <kk*******@hotmail.com> wrote in message
news:2m***********@dfw-service2.ext.ray.com...
Default locale setting uses 'do_grouping' that causes 'thousands_sep'
character to be inserted into the output. I don't know much about those
things, but read about locales in general. Could it be your code uses
different locales if a certain .so is loaded.


I guess we don't understand how the locale could vary based on whether
we use a .so or .a library, because the .a version works and the .so does
not.
Could you please shed a bit more light on this?

Thanks in advance,
Kyle


You haven't said where you ger those libraries from. Are you creating them
yourself, or are they some pre-existing libraries? If you're creating them,
it may be that the build settings (makefile, or whatever) has some control
over that aspect. If they're pre-existing, then perhaps whoever built them
might know the difference.

In any case, specifics about library types and the differences between them
are not part of the C++ language specification, and are platform-dependant.
You'd probably get more information in a newsgroup for your operating system
and/or compiler.

-Howard
Jul 23 '05 #7

"Howard" <al*****@hotmail.com> wrote in message
news:Bu********************@bgtnsc05-news.ops.worldnet.att.net...

"Kyle Kolander" <kk*******@hotmail.com> wrote in message
news:2m***********@dfw-service2.ext.ray.com...
Default locale setting uses 'do_grouping' that causes 'thousands_sep'
character to be inserted into the output. I don't know much about those things, but read about locales in general. Could it be your code uses
different locales if a certain .so is loaded.
I guess we don't understand how the locale could vary based on whether
we use a .so or .a library, because the .a version works and the .so does not.
Could you please shed a bit more light on this?

Thanks in advance,
Kyle


You haven't said where you ger those libraries from. Are you creating

them yourself, or are they some pre-existing libraries? If you're creating them, it may be that the build settings (makefile, or whatever) has some control
over that aspect. If they're pre-existing, then perhaps whoever built them might know the difference.

In any case, specifics about library types and the differences between them are not part of the C++ language specification, and are platform-dependant. You'd probably get more information in a newsgroup for your operating system and/or compiler.

-Howard


Thanks again... I posted to comp.unix.programmer and comp.unix.aix,
hopefully they will have advice.
They are our own libraries (lots of them written by lots of different
people) ;)
I'll check on the Makefiles.

Thanks,
Kyle
Jul 23 '05 #8

"Howard" <al*****@hotmail.com> wrote in message
news:Bu********************@bgtnsc05-news.ops.worldnet.att.net...

"Kyle Kolander" <kk*******@hotmail.com> wrote in message
news:2m***********@dfw-service2.ext.ray.com...
Default locale setting uses 'do_grouping' that causes 'thousands_sep'
character to be inserted into the output. I don't know much about those things, but read about locales in general. Could it be your code uses
different locales if a certain .so is loaded.
I guess we don't understand how the locale could vary based on whether
we use a .so or .a library, because the .a version works and the .so does not.
Could you please shed a bit more light on this?

Thanks in advance,
Kyle


You haven't said where you ger those libraries from. Are you creating

them yourself, or are they some pre-existing libraries? If you're creating them, it may be that the build settings (makefile, or whatever) has some control
over that aspect. If they're pre-existing, then perhaps whoever built them might know the difference.

In any case, specifics about library types and the differences between them are not part of the C++ language specification, and are platform-dependant. You'd probably get more information in a newsgroup for your operating system and/or compiler.

-Howard


Perhaps there is a new twist to this odd behavior...
We added these two lines of code immediately preceding our output of the
int:

string s = cout.getloc().name();
cout << s;

the printout was "C" in both spots (one of which works, and the other does
not).
So it looks like the locale is not being changed. How can the locale be
"C", which is the Default: ANSI-C convention, and still print out numbers
with commas?

So I guess my question would be if there is any other way that streams could
be manipulated into formatting numerics this way?

Thanks,
Kyle
Jul 23 '05 #9
Kyle Kolander wrote:
So I guess my question would be if there is any other way that streams could
be manipulated into formatting numerics this way?

Thanks,
Kyle


The following program demonstrates the only way I know of to create the
behavior you describe. Although it seems unlikely that anyone has done
this in your code, since the locale name is still "C" (when you create a
locale like this, it does not have a name).

-Alan

#include <iostream>
#include <string>
#include <locale>

class group_thousands : public std::numpunct<char>
{
protected :
virtual std::string do_grouping() const
{
return "\3" ;
}
} ;

int main()
{
std::cout.imbue(std::locale(std::cout.getloc(), new group_thousands())) ;

std::cout << 123456789 << std::endl ;
}

Jul 23 '05 #10
Alan Johnson wrote:
Kyle Kolander wrote:
So I guess my question would be if there is any other way that streams
could
be manipulated into formatting numerics this way?

Thanks,
Kyle


The following program demonstrates the only way I know of to create the
behavior you describe. Although it seems unlikely that anyone has done
this in your code, since the locale name is still "C" (when you create a
locale like this, it does not have a name).

-Alan

#include <iostream>
#include <string>
#include <locale>

class group_thousands : public std::numpunct<char>
{
protected :
virtual std::string do_grouping() const
{
return "\3" ;
}
} ;

int main()
{
std::cout.imbue(std::locale(std::cout.getloc(), new
group_thousands())) ;

std::cout << 123456789 << std::endl ;
}


As it turns out, we were able to eliminate the problem by removing calls
to a performance library called HPM (Hardware Performance Monitor)
Toolkit from IBM. Go figure... *sigh*. Thanks to all for your help!

Kyle
Jul 23 '05 #11

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Mazur | last post by:
MySQL 5.0 alpha (binary install) on Solaris 9 -or- RedHat 8.0 mysql-connector-java-3.0.8-stable ----------------------- Is there something different going on with JDBC and the alpha version...
10
by: Mathieu Malaterre | last post by:
Hello, I am trying to get rid a of sprintf in a c++ code, but I tried in several ways and couldn't figure out how to change: uint16_t group, uint16_t element; sprintf(buffer, "%04x|%04x",...
2
by: Gerhard Esterhuizen | last post by:
Hi, I am observing unexpected behaviour, in the form of a corrupted class member access, from a simple C++ program that accesses an attribute declared in a virtual base class via a chain of...
5
by: Robbert van Geldrop | last post by:
Hello, We run a very stable and well functioning ASP.Net 1.1 webservice using WSE 2.0 sp 3. Every now and then the following error appears in the system event log: HTTP/ASMX Message Receive...
0
by: mario.lat_ | last post by:
Hallo to all, I have write a little script for connecting to cisco router BUT I have a problem: I have to send to router all the commands and then I have to read the output. If I send a command1...
4
by: Scott F. Brown | last post by:
Greetings all... I was playing around with compressing streams and came across a behavior that I do not understand. I create a stream (input) from the contents of a textbox. That stream is...
7
by: Andrew McLean | last post by:
I have a bunch of csv files that have the following characteristics: - field delimiter is a comma - all fields quoted with double quotes - lines terminated by a *space* followed by a newline ...
0
by: =?Utf-8?B?UGF2aQ==?= | last post by:
Hi, I am getting the following error when I try to add web reference from Visual Studio 2005 for a third party web service There was an error downloading...
13
by: bintom | last post by:
I ran the following simple code in C++ and got unexpected results: float f = 139.4; cout << f; Output: 139.399994;
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.