manipulators act strange under g++/gcc-2.96

  • Thread starter Darius.Moos AT esigma-systems DOT de
  • Start date
D

Darius.Moos AT esigma-systems DOT de

Hi,

there seems to be a problem with manipulators in g++/gcc-2.96. First
some are not defined in std:: and second, when using this manipulators
on streams, they give strange results. A small test-programm to show
it:

#include <cstdlib>
#include <iostream>

int main(int argc, char **argv)
{
//std::cout << std::fixed << std::showpoint << 0.123456789 << std::endl;
std::cout << std::ios::fixed << std::ios::showpoint << 0.123456789 << std::endl;

exit(EXIT_SUCCESS);
}

Compiling and running this programm gives the following result:

~$ ./a.out
40962560.123457
~$

Anyone got an idea whats going wrong here ?

Thanks in advance for your help.

Darius.
 
J

John Harrison

Darius.Moos AT esigma-systems DOT de said:
Hi,

there seems to be a problem with manipulators in g++/gcc-2.96. First
some are not defined in std:: and second, when using this manipulators
on streams, they give strange results. A small test-programm to show
it:

#include <cstdlib>
#include <iostream>

int main(int argc, char **argv)
{
//std::cout << std::fixed << std::showpoint << 0.123456789 << std::endl;
std::cout << std::ios::fixed << std::ios::showpoint << 0.123456789 << std::endl;

exit(EXIT_SUCCESS);
}

Compiling and running this programm gives the following result:

~$ ./a.out
40962560.123457
~$

Anyone got an idea whats going wrong here ?

Thanks in advance for your help.

Darius.

I think you'll get more idea if you run the following

std::cout << std::ios::fixed << '|' << std::ios::showpoint << '|'
<< 0.123456789 << std::endl;

One of your manipulators is being output as the number 4096256 (presumably
its an address).

Upgrade to gcc v3 would be my advice.

john
 
D

Darius.Moos AT esigma-systems DOT de

Darius.Moos AT esigma-systems DOT de said:
there seems to be a problem with manipulators in g++/gcc-2.96. First
some are not defined in std:: and second, when using this manipulators
on streams, they give strange results. A small test-programm to show
[...]
I think you'll get more idea if you run the following
std::cout << std::ios::fixed << '|' << std::ios::showpoint <<
'|'
<< 0.123456789 << std::endl;

Gives:
~$ ./a.out
4096|256|0.123457
~$
One of your manipulators is being output as the number 4096256
(presumably its an address).

They seem to be part of an enumeration.
Upgrade to gcc v3 would be my advice.

Unfortunately this is no option as long as the current project runs.

Darius.
 
J

John Harrison

Darius.Moos AT esigma-systems DOT de said:
Darius.Moos AT esigma-systems DOT de said:
there seems to be a problem with manipulators in g++/gcc-2.96. First
some are not defined in std:: and second, when using this manipulators
on streams, they give strange results. A small test-programm to show
[...]
I think you'll get more idea if you run the following
std::cout << std::ios::fixed << '|' << std::ios::showpoint <<
'|'
<< 0.123456789 << std::endl;

Gives:
~$ ./a.out
4096|256|0.123457
~$
One of your manipulators is being output as the number 4096256
(presumably its an address).

They seem to be part of an enumeration.
Upgrade to gcc v3 would be my advice.

Unfortunately this is no option as long as the current project runs.

Darius.

What happens when you try

std::cout << std::fixed << std::showpoint << 0.123456789 <<
std::endl;

Thinking about it that is the correct code.

john
 
D

Darius.Moos AT esigma-systems DOT de

[...]
What happens when you try
std::cout << std::fixed << std::showpoint << 0.123456789 <<
std::endl;
Thinking about it that is the correct code.

They are not defined nor are they declared in std::, so the compiler
throws an appropriate error-message.

I could workaround the problem by (un)setting flags on the stream; just
wanted to use manipulators in the first place.

Darius.
 
J

Jacek Dziedzic

Darius.Moos AT esigma-systems DOT de said:
Hi,

there seems to be a problem with manipulators in g++/gcc-2.96. First
some are not defined in std:: and second, when using this manipulators
on streams, they give strange results. A small test-programm to show
it:

Yes, I've seen it also. Somehow under g++-2.9x when you output
certain manipulators to the stream you get their internal
enum values sent to the stream instead of these manipulators
acting, how bizzare!

The only two solutions I found were
a) upgrade to g++ 3.x, it's fixed in there
b) use cout.setf(...) instead -- it works fine.

HTH,
- J.
 
T

tom_usenet

message there seems to be a problem with manipulators in g++/gcc-2.96. First
some are not defined in std:: and second, when using this
manipulators on streams, they give strange results. A small
test-programm to show
[...]
What happens when you try
std::cout << std::fixed << std::showpoint << 0.123456789 <<
std::endl;
Thinking about it that is the correct code.

They are not defined nor are they declared in std::, so the compiler
throws an appropriate error-message.

I could workaround the problem by (un)setting flags on the stream; just
wanted to use manipulators in the first place.

Have you included <iomanip> (or <iomanip.h> with older compilers)? You
have to include the relevent header or things aren't defined...

Tom
 
D

Darius.Moos AT esigma-systems DOT de

Have you included <iomanip> (or <iomanip.h> with older compilers)? You
have to include the relevent header or things aren't defined...

No, in the small test-programm i did not, since afaik <iomanip> just
defines/declares manipulators that take an argument.
Just to be sure it does not make any difference, i included <iomanip>
in the small test-programm. It did not fix the problem.

Darius.
 
D

Dave Moore

Darius.Moos AT esigma-systems DOT de said:
Hi,

there seems to be a problem with manipulators in g++/gcc-2.96. First
some are not defined in std:: and second, when using this manipulators
on streams, they give strange results. A small test-programm to show
it:

#include <cstdlib>
#include <iostream>

int main(int argc, char **argv)
{
//std::cout << std::fixed << std::showpoint << 0.123456789 << std::endl;
std::cout << std::ios::fixed << std::ios::showpoint << 0.123456789 << std::endl;

exit(EXIT_SUCCESS);
}

Compiling and running this programm gives the following result:

~$ ./a.out
40962560.123457
~$

Anyone got an idea whats going wrong here ?

Thanks in advance for your help.

Darius.

Well .. the manipulators are defined in <iomanip>; including that file
will put them in the std namespace as you were originally expecting.

What is happening in your code is that you are seeing the values of
std::ios::fixed and std::ios::showpoint on the stream. They are *not*
manipulators, or even functions, but rather implementation defined
flags for adding characteristics to the output stream. Try putting
spaces or tabs in between them to see which is which 8*).

As an aside, I think you should use "return EXIT_SUCCESS" at the end
of your program, rather than the call to exit.

HTH, Dave Moore
 
R

Richard Herring

Jacek Dziedzic said:
Yes, I've seen it also. Somehow under g++-2.9x when you output
certain manipulators to the stream you get their internal
enum values sent to the stream instead of these manipulators
acting, how bizzare!

The fmtflags values are members of ios_base; the manipulator functions
are not.
 
R

Richard Herring

Darius.Moos AT said:
No, in the small test-programm i did not, since afaik <iomanip> just
defines/declares manipulators that take an argument.
Just to be sure it does not make any difference, i included <iomanip>
in the small test-programm. It did not fix the problem.
You could try including <ios> which, according to 27.4, is where the
manipulator functions are supposed to be declared.
 
D

Darius.Moos AT esigma-systems DOT de

Well .. the manipulators are defined in <iomanip>; including that file
will put them in the std namespace as you were originally expecting.

~$ g++ ./test.cc
../test.cc: In function `int main (int, char **)':
../test.cc:10: `::fixed' undeclared (first use here)
../test.cc:10: `::showpoint' undeclared (first use here)
~$
What is happening in your code is that you are seeing the values of
std::ios::fixed and std::ios::showpoint on the stream. They are *not*
manipulators, or even functions, but rather implementation defined flags
for adding characteristics to the output stream. Try putting spaces or
tabs in between them to see which is which 8*).

Thanks for the clarification.

Darius.
 
T

tom_usenet

No, in the small test-programm i did not, since afaik <iomanip> just
defines/declares manipulators that take an argument.

Good point.
Just to be sure it does not make any difference, i included <iomanip>
in the small test-programm. It did not fix the problem.

Searching through the old GCC (2.96) headers, it looks like they just
didn't implement those manipulators (showpoint and fixed). Obvious
that version doesn't pretend to follow the C++ standard - the streams
aren't even templated.

The manipulators should be in the <ios> header IIRC - #including
<iostream> won't necessarily bring them in. endl and flush are in
<ostream>, and again, that should be explicitly included for the code
to be standard.

For old GCC you could implement the manipulators yourself...

Tom
 
D

Darius.Moos AT esigma-systems DOT de

]
You could try including <ios> which, according to 27.4, is where the
manipulator functions are supposed to be declared.

~$ g++ ./test.cc
../test.cc:4:15: ios: No such file or directory
~$
 
D

Darius.Moos AT esigma-systems DOT de

]
Searching through the old GCC (2.96) headers, it looks like they just
didn't implement those manipulators (showpoint and fixed). Obvious that
version doesn't pretend to follow the C++ standard - the streams aren't
even templated.
The manipulators should be in the <ios> header IIRC - #including
<iostream> won't necessarily bring them in. endl and flush are in
<ostream>, and again, that should be explicitly included for the code to
be standard.

~$ g++ ./test.cc
../test.cc:4:15: ios: No such file or directory
~$
For old GCC you could implement the manipulators yourself...

Yes, or use flags on the stream.

Darius.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top