is it a bug in gcc2.3.2?

G

gukn9700

the following code cannot pass the compiler:

#include <fstream>
#include <iostream>

using namespace std;

int main()
{
fstream outfile("i:\\test.txt", ios_base::in | ios_base::eek:ut);
long lFlag = outfile.flags();

outfile.setf(ios_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_fstream<char,
std::char_traits<char> >::setf(const std::_Ios_Openmode&)'
i:/mingw/include/c++/3.2/bits/ios_base.h:342: candidates are:
std::_Ios_Fmtflags std::ios_base::setf(std::_Ios_Fmtflags)
i:/mingw/include/c++/3.2/bits/ios_base.h:350:
std::_Ios_Fmtflags std::ios_base::setf(std::_Ios_Fmtflags,
std::_Ios_Fmtflags)

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?
 
J

John Harrison

gukn9700 said:
the following code cannot pass the compiler:

#include <fstream>
#include <iostream>

using namespace std;

int main()
{
fstream outfile("i:\\test.txt", ios_base::in | ios_base::eek:ut);
long lFlag = outfile.flags();

outfile.setf(ios_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_fstream<char,
std::char_traits<char> >::setf(const std::_Ios_Openmode&)'
i:/mingw/include/c++/3.2/bits/ios_base.h:342: candidates are:
std::_Ios_Fmtflags std::ios_base::setf(std::_Ios_Fmtflags)
i:/mingw/include/c++/3.2/bits/ios_base.h:350:
std::_Ios_Fmtflags std::ios_base::setf(std::_Ios_Fmtflags,
std::_Ios_Fmtflags)

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?

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
 

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,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top