473,386 Members | 1,827 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,386 software developers and data experts.

manipulators act strange under g++/gcc-2.96

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.
Jul 22 '05 #1
16 1931

"Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in message
news:c6************@ID-193014.news.uni-berlin.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.


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
Jul 22 '05 #2
On Tue, 27 Apr 2004 13:07:18 +0200, John Harrison wrote:
"Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in
message news:c6************@ID-193014.news.uni-berlin.de...
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.
Jul 22 '05 #3

"Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in message
news:c6************@ID-193014.news.uni-berlin.de...
On Tue, 27 Apr 2004 13:07:18 +0200, John Harrison wrote:
"Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in
message news:c6************@ID-193014.news.uni-berlin.de...
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

Jul 22 '05 #4
On Tue, 27 Apr 2004 14:05:43 +0200, John Harrison wrote:
> "Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in
> message news:c6************@ID-193014.news.uni-berlin.de...
>> 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.

Darius.
Jul 22 '05 #5
Darius.Moos AT esigma-systems DOT de wrote:
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.
Jul 22 '05 #6
On Tue, 27 Apr 2004 14:14:19 +0200, "Darius.Moos AT esigma-systems DOT
de" <pf*********@gmx.de> wrote:
On Tue, 27 Apr 2004 14:05:43 +0200, John Harrison wrote:
> "Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in
> message news:c6************@ID-193014.news.uni-berlin.de...
>> 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
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #7
On Tue, 27 Apr 2004 14:46:05 +0200, tom_usenet wrote:
On Tue, 27 Apr 2004 14:14:19 +0200, "Darius.Moos AT esigma-systems DOT
de" <pf*********@gmx.de> wrote:
On Tue, 27 Apr 2004 14:05:43 +0200, John Harrison wrote:
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...


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.
Jul 22 '05 #8
"Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in message news:<c6************@ID-193014.news.uni-berlin.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.


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
Jul 22 '05 #9
On Tue, 27 Apr 2004 14:52:22 +0200, "Darius.Moos AT esigma-systems DOT
de" <pf*********@gmx.de> wrote:
On Tue, 27 Apr 2004 14:46:05 +0200, tom_usenet wrote:
On Tue, 27 Apr 2004 14:14:19 +0200, "Darius.Moos AT esigma-systems DOT
de" <pf*********@gmx.de> wrote:
On Tue, 27 Apr 2004 14:05:43 +0200, John Harrison wrote:
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...


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
--
C++ FAQ: http://www.parashift.com/c++-faq-lite/
C FAQ: http://www.eskimo.com/~scs/C-faq/top.html
Jul 22 '05 #10
In message <c6**********@korweta.task.gda.pl>, Jacek Dziedzic
<ja*************@janowo.net> writes
Darius.Moos AT esigma-systems DOT de wrote:
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 fmtflags values are members of ios_base; the manipulator functions
are not.
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.


--
Richard Herring
Jul 22 '05 #11
In message <c6************@ID-193014.news.uni-berlin.de>, Darius.Moos AT
esigma-systems DOT de <pf*********@gmx.de> writes
On Tue, 27 Apr 2004 14:46:05 +0200, tom_usenet wrote:
On Tue, 27 Apr 2004 14:14:19 +0200, "Darius.Moos AT esigma-systems DOT
de" <pf*********@gmx.de> wrote:
On Tue, 27 Apr 2004 14:05:43 +0200, John Harrison wrote:
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...


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.

--
Richard Herring
Jul 22 '05 #12
On Tue, 27 Apr 2004 15:54:22 +0200, Dave Moore wrote:
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.
Jul 22 '05 #13
On Tue, 27 Apr 2004 16:05:50 +0200, Richard Herring wrote:
[...]
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
~$
Jul 22 '05 #14
On Tue, 27 Apr 2004 16:14:50 +0200, tom_usenet wrote:
[...]
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.
Jul 22 '05 #15
In message <30**************************@posting.google.com >, Dave Moore
<dt*****@rijnh.nl> writes
"Darius.Moos AT esigma-systems DOT de" <pf*********@gmx.de> wrote in
message news:<c6************@ID-193014.news.uni-berlin.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.
Well .. the manipulators are defined in <iomanip>;


Only the ones that take arguments.
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


--
Richard Herring
Jul 22 '05 #16
"Darius.Moos AT esigma-systems DOT de" wrote:

there seems to be a problem with manipulators in g++/gcc-2.96.


This is an unstable development version of gcc.
If you can't go to gcc 3, at least see if you can go to gcc 2.95.2.

More info: http://gcc.gnu.org/gcc-2.96.html
Jul 22 '05 #17

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

Similar topics

4
by: destroyedlolo | last post by:
Hi all, I just upgrade my workstation to Gcc 3.3, and I got a very strange probleme with casting : I got an error if I try to get the adress of a "casted" pointer. ---- dumy example source...
6
by: Paul Davis | last post by:
I have some simple test code, which is copied pretty much verbatim from Josuttis (although he doesn't give complete examples): #include <iostream> main() { cout << hex << 1 << endl; std::cout...
1
by: Andy | last post by:
1) Are the manipulators like std::endl and std::ends independent of character set. That is, can I use the same manipulators in both the following cases: a) <code> std::basic_stringstream<char>...
3
by: Lionel B | last post by:
In an overloaded output operator for a class I want to detect ostream manipulators such as flush, endl, ends, etc. I am stymied by how to do this; here's a minimal program indicating my problem: ...
8
by: grundmann | last post by:
Hello, i got a strange compiler error. When compiling the following: // forward declarations typedef AvlTree<LineSegment,LineSegmentComperator> LSTree; void handleEventPoint (const...
1
by: | last post by:
The code: // Block 1 // cout << "Integrating " << str << " on " << endl << " exact answer: " << exact << endl << flush; #if 0 // Block 2
7
by: Flash Gordon | last post by:
Reading the standard, va_list is an object type (, so I believe the following should be possible: #include <stdarg.h> void foo(va_list *arg) { /* do some stuff which conditionally might read...
1
by: zl2k | last post by:
hi, all I am not sure of this question is suitable for the c++ language group but still hope the experts here can give me some hints. I am using gcc 3.4.4 in fc3 and got a very strang error when...
9
by: David W | last post by:
A colleague wants to do this with a std::ostream: os << fahrenheit << 37.0; This would output 98.6 (i.e., Celsius --Fahrenheit). I've already suggested os << fahrenheit(37.0), but he doesn't...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.