std::uppercase & gcc

Discussion in 'C++' started by Paul Schwann, Jul 29, 2003.

  1. Paul Schwann

    Paul Schwann Guest

    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
     
    Paul Schwann, Jul 29, 2003
    #1
    1. Advertising

  2. Paul Schwann

    Greg P. Guest

    "Paul Schwann" <> wrote in message
    news:3f262d58$0$262$...
    > #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! =)
     
    Greg P., Jul 29, 2003
    #2
    1. Advertising

  3. Paul Schwann

    Paul Schwann Guest

    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
     
    Paul Schwann, Jul 29, 2003
    #3
  4. Paul Schwann

    Greg P. Guest

    "Paul Schwann" <> wrote in message
    news:3f263a13$0$262$...
    > 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"
     
    Greg P., Jul 29, 2003
    #4
  5. Paul Schwann

    Paul Schwann Guest

    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
     
    Paul Schwann, Jul 29, 2003
    #5
  6. "Paul Schwann" <> wrote in message
    news:3f264c6e$0$254$...
    > #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.
     
    Jacek Dziedzic, Jul 29, 2003
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.

Share This Page