g++ compilation error
Author |
Message |
deltatux
![](http://compsci.ca/v3/uploads/user_avatars/2510662304931ac0b5cb22.png)
|
Posted: Mon Feb 23, 2009 3:44 pm Post subject: g++ compilation error |
|
|
Hey guys,
I'm quite confused here. My program works perfectly when compiled on Visual Studio 2008 but it doesn't compile on G++.
I don't even understand the error. I know that the ifstream is part of the C++ standard library so it makes even less sense:
Quote:
isbnprefix.cpp: In function 'int registered(FILE*, int)':
isbnprefix.cpp:32: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(FILE*&)'
/usr/include/c++/4.1.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)
isbnprefix.cpp: In function 'int minNoDigits(FILE*, int)':
isbnprefix.cpp:42: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(FILE*&)'
/usr/include/c++/4.1.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)
isbnprefix.cpp: In function 'int registered(FILE*, int, int)':
isbnprefix.cpp:65: error: no matching function for call to 'std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(FILE*&)'
/usr/include/c++/4.1.2/fstream:442: note: candidates are: std::basic_ifstream<_CharT, _Traits>::basic_ifstream(const char*, std::_Ios_Openmode) [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/fstream:428: note: std::basic_ifstream<_CharT, _Traits>::basic_ifstream() [with _CharT = char, _Traits = std::char_traits<char>]
/usr/include/c++/4.1.2/iosfwd:89: note: std::basic_ifstream<char, std::char_traits<char> >::basic_ifstream(const std::basic_ifstream<char, std::char_traits<char> >&)
My isbnprefix.cpp as follows:
code: |
/* isbnprefix.cpp
* Assignment 1's ISBN prefix program file.
* Copyright (C) 2009 Adrien Kwok.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License Version 3
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <[LINK REMOVED]>.
*
*/
#include "stdheader.h"
#include "prefix.h"
void seekStart(FILE* fp) {
fseek(fp, 0, SEEK_SET);
}
FILE* open(const char* filename){
FILE* fp = new FILE;
fp = fopen (filename, "r");
return fp;
}
int registered(FILE* fp, int area){
seekStart(fp);
ifstream in(fp);
while (!in.eof()) {
int area0, minPublisher, maxPublisher;
in >> area0 >> minPublisher >> maxPublisher;
if (area0 == area) return true;
}
return false;
}
int minNoDigits(FILE* fp, int area){
seekStart(fp);
ifstream in(fp);
while (!in.eof()) {
// read one line
int area0, minPublisher, maxPublisher;
in >> area0 >> minPublisher >> maxPublisher;
cout << maxPublisher;
// determine the max number of digits
if (area == area0) {
if (maxPublisher <= 9) return 1;
if (maxPublisher <= 99) return 2;
if (maxPublisher <= 999) return 3;
if (maxPublisher <= 9999) return 4;
if (maxPublisher <= 99999) return 5;
if (maxPublisher <= 999999) return 6;
return 7;
}
}
return 0;
}
int registered(FILE* fp, int area, int publisher){
seekStart(fp);
ifstream in(fp);
while (in) {
int area0, minPublisher, maxPublisher;
in >> area0 >> minPublisher >> maxPublisher;
if (area0 == area) {
if (minPublisher <= publisher && publisher <= maxPublisher) return true;
}
}
return false;
}
int close (FILE* fp){
int err = fclose(fp);
return err == 0 ? true : false;
}
|
Thanks,
deltatux |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
DemonWasp
|
|
|
|
![](images/spacer.gif) |
saltpro15
![](http://compsci.ca/v3/uploads/user_avatars/9776171634ced6278d14c2.png)
|
Posted: Mon Feb 23, 2009 4:48 pm Post subject: RE:g++ compilation error |
|
|
... I was going to say you need the #include <fstream> but demonwasp's answer makes a lot more sense |
|
|
|
|
![](images/spacer.gif) |
wtd
|
Posted: Mon Feb 23, 2009 8:20 pm Post subject: RE:g++ compilation error |
|
|
You are not going to make any substantial headway until you ditch the C/C++ bastardization. |
|
|
|
|
![](images/spacer.gif) |
|
|