is it a bug in gcc2.3.2?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • gukn9700

    is it a bug in gcc2.3.2?

    the following code cannot pass the compiler:

    #include <fstream>
    #include <iostream>

    using namespace std;

    int main()
    {
    fstream outfile("i:\\te st.txt", ios_base::in | ios_base::out);
    long lFlag = outfile.flags() ;

    outfile.setf(io s_base::app);
    cout << hex << "Original flag : " << lFlag << '\n'
    << "Now flag : " << outfile.flags() << '\n';

    if (outfile.flags( ) & ios_base::app)
    cout << "append bit set!\n";

    char ch;
    while (cin >> ch)
    outfile << ch;

    cout << '\n';
    outfile.seekg(0 );
    while (outfile.get(ch ))
    cout << ch;
    cout << '\n';

    return 0;
    }

    the compiler returns the errors:

    test3.cpp: In function `int main()':
    test3.cpp:11: no matching function for call to
    `std::basic_fst ream<char,
    std::char_trait s<char> >::setf(const std::_Ios_Openm ode&)'
    i:/mingw/include/c++/3.2/bits/ios_base.h:342: candidates are:
    std::_Ios_Fmtfl ags std::ios_base:: setf(std::_Ios_ Fmtflags)
    i:/mingw/include/c++/3.2/bits/ios_base.h:350:
    std::_Ios_Fmtfl ags std::ios_base:: setf(std::_Ios_ Fmtflags,
    std::_Ios_Fmtfl ags)

    but there is no problem with both bcc5.5 and vc6.0.

    my system is Windows2000 and i use the gcc2.3.2 shipped with
    mingw2.0.3.

    what's the matter with gcc2.3.2 or my program?
  • John Harrison

    #2
    Re: is it a bug in gcc2.3.2?


    "gukn9700" <gukn9700@hotma il.com> wrote in message
    news:5g1ahv0n38 uf35fvngp59cf3o itrc1ts75@4ax.c om...[color=blue]
    > the following code cannot pass the compiler:
    >
    > #include <fstream>
    > #include <iostream>
    >
    > using namespace std;
    >
    > int main()
    > {
    > fstream outfile("i:\\te st.txt", ios_base::in | ios_base::out);
    > long lFlag = outfile.flags() ;
    >
    > outfile.setf(io s_base::app);
    > cout << hex << "Original flag : " << lFlag << '\n'
    > << "Now flag : " << outfile.flags() << '\n';
    >
    > if (outfile.flags( ) & ios_base::app)
    > cout << "append bit set!\n";
    >
    > char ch;
    > while (cin >> ch)
    > outfile << ch;
    >
    > cout << '\n';
    > outfile.seekg(0 );
    > while (outfile.get(ch ))
    > cout << ch;
    > cout << '\n';
    >
    > return 0;
    > }
    >
    > the compiler returns the errors:
    >
    > test3.cpp: In function `int main()':
    > test3.cpp:11: no matching function for call to
    > `std::basic_fst ream<char,
    > std::char_trait s<char> >::setf(const std::_Ios_Openm ode&)'
    > i:/mingw/include/c++/3.2/bits/ios_base.h:342: candidates are:
    > std::_Ios_Fmtfl ags std::ios_base:: setf(std::_Ios_ Fmtflags)
    > i:/mingw/include/c++/3.2/bits/ios_base.h:350:
    > std::_Ios_Fmtfl ags std::ios_base:: setf(std::_Ios_ Fmtflags,
    > std::_Ios_Fmtfl ags)
    >
    > but there is no problem with both bcc5.5 and vc6.0.
    >
    > my system is Windows2000 and i use the gcc2.3.2 shipped with
    > mingw2.0.3.
    >
    > what's the matter with gcc2.3.2 or my program?[/color]

    Your program of course. setf is for format flags, ios_base::app is an open
    mode flag. Probably those other compilers defined format flags and open mode
    flags as both being type long, so they could not detect this error. gcc is
    superior (in this respect at least).

    john


    Comment

    Working...