c++ code works in gcc2.9 not in gcc3.2.2

Discussion in 'C++' started by Philip Goisman, Jan 22, 2004.

  1. Hi,

    Hope someone can help. I have the following c++ program which compiles
    fine in gcc2.96, but won't compile in gcc3.2.2:

    //FMain.cpp

    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <sstream>

    int main()
    {
    int RunCurr = 66;
    char* before = { "data/geom." };
    char* after = { ".xml" };

    std::eek:stringstream GeomFileName;

    GeomFileName << before << setw(6)
    << setfill (48) << dec << RunCurr << after << ends ;

    cout << GeomFileName.str() << endl;

    return 0;
    }

    Any help is appreciated.

    Regards,

    Philip
     
    Philip Goisman, Jan 22, 2004
    #1
    1. Advertising

  2. Philip Goisman wrote:

    > Hi,
    >
    > Hope someone can help. I have the following c++ program which compiles
    > fine in gcc2.96, but won't compile in gcc3.2.2:


    What errors did it give?

    >
    > //FMain.cpp
    >
    > #include <stdlib.h>
    > #include <stdio.h>
    > #include <iostream>
    > #include <iomanip>
    > #include <string>
    > #include <sstream>
    >
    > int main()
    > {
    > int RunCurr = 66;
    > char* before = { "data/geom." };
    > char* after = { ".xml" };
    >
    > std::eek:stringstream GeomFileName;
    >
    > GeomFileName << before << setw(6)
    > << setfill (48) << dec << RunCurr << after << ends ;


    It's called std::ends, and you shouldn't be using it.

    >
    > cout << GeomFileName.str() << endl;


    std::cout and std::endl.

    >
    > return 0;
    > }
    >
    > Any help is appreciated.
    >
    > Regards,
    >
    > Philip


    -Kevin
    --
    My email address is valid, but changes periodically.
    To contact me please use the address from a recent posting.
     
    Kevin Goodsell, Jan 22, 2004
    #2
    1. Advertising

  3. "Philip Goisman" <> wrote in message
    news:...
    > Hi,
    >
    > Hope someone can help. I have the following c++ program which

    compiles
    > fine in gcc2.96, but won't compile in gcc3.2.2:
    >
    > //FMain.cpp
    >
    > #include <stdlib.h>
    > #include <stdio.h>
    > #include <iostream>
    > #include <iomanip>
    > #include <string>
    > #include <sstream>
    >
    > int main()
    > {
    > int RunCurr = 66;
    > char* before = { "data/geom." };
    > char* after = { ".xml" };
    >
    > std::eek:stringstream GeomFileName;
    >
    > GeomFileName << before << setw(6)
    > << setfill (48) << dec << RunCurr << after << ends

    ;
    >
    > cout << GeomFileName.str() << endl;
    >
    > return 0;
    > }



    There are two problems:

    1. The i/o manipulators are in namespace std.
    2. GCC 3.2 is finding setfill(48) ambiguous. I tried your code on
    several modern compilers, and only como 4.3.3 failed to complain of
    this ambiguity. Off the top of my head, I'm not sure whose right.

    Anyway, the following compiles on GCC 3.2:

    int main()
    {
    int RunCurr = 66;
    char* before = { "data/geom." };
    char* after = { ".xml" };

    std::eek:stringstream GeomFileName;

    GeomFileName << before << std::setw(6)
    << std::setfill((char) 48)
    << std::dec << RunCurr << after << std::ends ;

    std::cout << GeomFileName.str() << std::endl;

    return 0;
    }

    You could also use something like this, which is easier to read.

    const char zero = 48;
    GeomFileName << before << std::setw(6)
    << std::setfill(zero)
    << std::dec << RunCurr << after << std::ends ;

    HTH

    Jonathan
     
    Jonathan Turkanis, Jan 22, 2004
    #3
  4. Philip Goisman

    red floyd Guest

    Jonathan Turkanis wrote:
    > "Philip Goisman" <> wrote in message
    > news:...
    >
    >>Hi,
    >>
    >> Hope someone can help. I have the following c++ program which

    >
    > compiles
    >
    >>fine in gcc2.96, but won't compile in gcc3.2.2:
    >>
    >>//FMain.cpp
    >>
    >>#include <stdlib.h>
    >>#include <stdio.h>
    >>#include <iostream>
    >>#include <iomanip>
    >>#include <string>
    >>#include <sstream>
    >>
    >>int main()
    >> {
    >> int RunCurr = 66;
    >> char* before = { "data/geom." };
    >> char* after = { ".xml" };
    >>
    >> std::eek:stringstream GeomFileName;
    >>
    >> GeomFileName << before << setw(6)
    >> << setfill (48) << dec << RunCurr << after << ends

    >
    > ;
    >
    >> cout << GeomFileName.str() << endl;
    >>
    >> return 0;
    >> }

    >
    >
    >
    > There are two problems:
    >
    > 1. The i/o manipulators are in namespace std.
    > 2. GCC 3.2 is finding setfill(48) ambiguous. I tried your code on
    > several modern compilers, and only como 4.3.3 failed to complain of
    > this ambiguity. Off the top of my head, I'm not sure whose right.
    >
    > Anyway, the following compiles on GCC 3.2:
    >
    > int main()
    > {
    > int RunCurr = 66;
    > char* before = { "data/geom." };
    > char* after = { ".xml" };
    >
    > std::eek:stringstream GeomFileName;
    >
    > GeomFileName << before << std::setw(6)
    > << std::setfill((char) 48)
    > << std::dec << RunCurr << after << std::ends ;
    >
    > std::cout << GeomFileName.str() << std::endl;
    >
    > return 0;
    > }
    >
    > You could also use something like this, which is easier to read.
    >
    > const char zero = 48;
    > GeomFileName << before << std::setw(6)
    > << std::setfill(zero)
    > << std::dec << RunCurr << after << std::ends ;
    >

    even better would be:

    GeomFileName << before << std::setw(6)
    << std::setfill('0')
    << std::dec << RunCurr << after << std::ends;

    That way you don't have the implicit reliance on ASCII encoding of
    character values.
     
    red floyd, Jan 22, 2004
    #4
  5. "Jonathan Turkanis" <> wrote in message
    news:buplc5$k8ctv$-berlin.de...
    >


    > There are two problems:
    >
    > 1. The i/o manipulators are in namespace std.


    Also 'cout' is in std.

    > this ambiguity. Off the top of my head, I'm not sure whose right.


    I'm also not sure who's right. :)

    Jonathan
     
    Jonathan Turkanis, Jan 22, 2004
    #5
  6. "red floyd" <> wrote in message
    news:iXYPb.4686$...
    > Jonathan Turkanis wrote:
    > > "Philip Goisman" <> wrote in message


    > >
    > > You could also use something like this, which is easier to read.
    > >
    > > const char zero = 48;
    > > GeomFileName << before << std::setw(6)
    > > << std::setfill(zero)
    > > << std::dec << RunCurr << after << std::ends

    ;
    > >

    > even better would be:
    >
    > GeomFileName << before << std::setw(6)
    > << std::setfill('0')
    > << std::dec << RunCurr << after <<

    std::ends;
    >
    > That way you don't have the implicit reliance on ASCII encoding of
    > character values.


    Certainly, if that's what the OP wants. He went to the trouble of
    specifying 48, though, so I'm assuming he had some good reason.

    Jonathan
     
    Jonathan Turkanis, Jan 22, 2004
    #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.
Similar Threads
  1. gukn9700

    is it a bug in gcc2.3.2?

    gukn9700, Jul 16, 2003, in forum: C++
    Replies:
    1
    Views:
    400
    John Harrison
    Jul 16, 2003
  2. James Ying
    Replies:
    2
    Views:
    591
    James Ying
    Oct 28, 2003
  3. John Black
    Replies:
    1
    Views:
    343
    Karthiik Kumar
    Aug 28, 2004
  4. Bart Blommerde

    using hash_set in gcc3.3

    Bart Blommerde, Oct 13, 2004, in forum: C++
    Replies:
    5
    Views:
    520
    John Harrison
    Oct 13, 2004
  5. Replies:
    2
    Views:
    365
    red floyd
    May 18, 2005
Loading...

Share This Page