std::uppercase & gcc

P

Paul Schwann

Hi everybody,

I have a problem with the following code:

#include <iostream>

int main(void) {
std::cout << std::hex << std::uppercase << 31 <<std::endl;

return 0;
}

It compiles fine with msvc 6.0 (windows) and gcc 3.3 (linux). If I
compile it under linux with some older gcc (2.95.3), it always complains
about the "uppercase" modifier, like:

test.cpp: In function `int main()':
test.cpp:4: `::uppercase' undeclared (first use here)

Question is: What can I do to make it run on all platforms: windows (vc
6.0) and linux/solaris (gcc 2.95, 3.3)?

Thanks for your help,
Paul
 
G

Greg P.

Paul Schwann said:
#include <iostream>

int main(void) {
std::cout << std::hex << std::uppercase << 31 <<std::endl;

return 0;
}
Make sure that your iostream header is including the ios_base. Do a grep:
grep uppercase *ios*.h and make sure it's contained within it. Some older
implementations require a separate iosbase. If you are lazy, you can try
including ios which is under c++/bits/ios_base.h or simply <ios>.

Also, do not use void as the argument to main, either use main() or main(int
argc, char* argv[]) as the standard commands! =)
 
P

Paul Schwann

Thank you very much Greg, for your fast answer!

I'm afraid, it does not help or I do not understand exactly what you
mean. Doing a grep over my include paths only has one result: there is
an "uppercase" definition in a file "streambuf.h". Including it in my
little app does not help.
The files "ios" or "ios_base.h" you mentioned do not exist. Do I really
have to upgrade all the linux machines to gcc 3.3 just to run that
little stupid application?!

Regards
Paul
 
G

Greg P.

Paul Schwann said:
Thank you very much Greg, for your fast answer!

I'm afraid, it does not help or I do not understand exactly what you
mean. Doing a grep over my include paths only has one result: there is
an "uppercase" definition in a file "streambuf.h". Including it in my
little app does not help.
The files "ios" or "ios_base.h" you mentioned do not exist. Do I really
have to upgrade all the linux machines to gcc 3.3 just to run that
little stupid application?!

Sadly, I think you may. I don't remember ever having that problem with gcc
2.9x.x, though I also don't remember having to use std::uppercase.

For some reason your implementation of GCC's C++ library is not holding true
to the C++ standard. You should have a standard include of <ios>. Telling me
you don't have it makes me wonder if you have some missing files.

When you grep'd, did the result show the definition of uppercase as 0x4000?
--

Regards,
Greg P.

Golden Rule of Open Source Programming:
"Don't whine about something unless you plan to implement it yourself"
 
P

Paul Schwann

In streambuf.h, a class "ios" is defined having an enumeration with "...
uppercase=_IO_UPPERCASE, ..." where _IO_UPPERCASE comes from libio.h and
has the value 01000 (octal 1000?).

If I modify my little program like this:

#include <iostream>

int main(void) {
std::cout.setf(ios::uppercase);
std::cout << std::hex << 31 <<std::endl;

return 0;
}

it compiles and runs just fine on linux with gcc 2.95.3. Of course, this
does not compile with gcc 3.3 nor vc6. Probably, I have to create 2
different versions of that application. Unbeliveable.

Thanks anyway Greg!

Regards, Paul
 
J

Jacek Dziedzic

Paul Schwann said:
#include <iostream>

int main(void) {
std::cout.setf(ios::uppercase);
std::cout << std::hex << 31 <<std::endl;

return 0;
}

it compiles and runs just fine on linux with gcc 2.95.3.
Of course, this does not compile with gcc 3.3 nor vc6.

Possibly it would help to change that "ios::uppercase"
to "std::ios::uppercase", but I don't have gcc 3.3 handy,
so I can't check that.

I must say you're not the only one with "silly" stream
issues when it comes to gcc differences. I remember
having similar problems with stream modifiers. In the
craziest of cases one gcc version recognized a modifier
(ios::showpoint was it?) and behaved correctly, whereas
the other... dumped the value of the modifier into the
stream as if it was a number, unbelievable. Perhaps the
more experienced people here could help -- I'm only
aware there's a bit of a mess when it comes to streams
and gcc.

HTH,
- J.
 

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

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,901
Latest member
Noble71S45

Latest Threads

Top