PDA

View Full Version : Strange ifstream problem...



Waldo2k2
06-06-2002, 09:19 PM
I have the following code:


#include <iostream>
#include <fstream>
using namespace std;

char academics[1000000];
char sports[1000000];
char extra[1000000];
char id[20];
bool loggedIn=0;




int main()
{
do{
cout<<"Enter ID Number"<<endl;
cin>>id;

if (id=="04390") {
loggedIn=1;
break;
}else{
//repeat above for all other valid id numbers, sort of a catch all so that a slipped finger doesn't make their portfolio unviewable through the viewer.html construct...
loggedIn=0;
break;
}
}while (loggedIn==0);
//read files into strings....

//note that, when using for real project...use fin("f:\\users\\whatever double slash"id"double slash academics.portfolio)...

ifstream afin("c:\\drew\\ElectronicPortfolioFiles\\academics.port folio");
if (!afin.is_open) {
cerr<<"Error Opening File: 'academics.portfolio'"<<endl;
cerr<<"Make Sure The File Exists And Is In Your ID Folder"<<endl;
exit(1);
}
afin>>academics;
afin.close();

ifstream sfin("c:\\drew\\ElectronicPortfolioFiles\\sports.portfol io");
if (!sfin.is_open) {
cerr<<"Error Opening File: 'sports.portfolio'"<<endl;
cerr<<"Make Sure The File Exists And Is In Your ID Folder"<<endl;
exit(1);
}
sfin>>sports;
sfin.close();

ifstream efin("c:\\drew\\ElectronicPortfolioFiles\\extra.portfoli o");
if (!efin.is_open) {
cerr<<"Error Opening File: 'extra.portfolio'"<<endl;
cerr<<"Make Sure The File Exists And Is In Your ID Folder"<<endl;
exit(1);
}
efin>>extra;
efin.close();
char fileExtension[]=".xml";
char* fileName=strcat(id,fileExtension);


ofstream fout(fileName);
if (!fout.is_open) {
cerr<<"Error Compiling Portfolio, Sorry For The Inconvenience."<<endl;
exit(1);
}
fout<<"<?xml version='1.0'?>"<<'\n'<<"<!DOCYPE portfolio ["<<'\n'<<"<!ELEMENT portfolio (academics, sports, extra)>"<<'\n'<<"!ELEMENT academics (#PCDATA) >"<<'\n'<<"!ELEMENT sports (#PCDATA) >"<<'\n'<<"!ELEMENT extra (#PCDATA) >"<<'\n'<<"<portfolio>"<<'\n';
fout<<"<academics>"<<'\n'<<academics<<'\n'<<"</academics>"<<'\n'<<"<sports>"<<'\n'<<sports<<'\n'<<"</sports>"<<'\n'<<"<extra>"<<'\n'<<extra<<'\n'<<"</extra>"<<'\n'<<"</portfolio>";
fout.close();


return 0;
}

upon compiling, i receive the following error:
member function must be called, or it's address taken in function main()
it says that error occurs on a few lines, each happens to be one where i use the ifstream operator....whats up with this code?

Monster
06-07-2002, 04:54 AM
I tried to compile your code and got 4 errors, all the same.
It's because of the is_open. This is a function and not a variable.
Change it to:

if( !sfin.is_open() )

Waldo2k2
06-07-2002, 04:55 PM
oh man!
I've used that code a dozen times before, i can't believe i screwed that up! That will teach me to write code on the back of a electrical schematic during breaktime...anyhow thank you very much, i probably never would have caught that. :)

sean
06-08-2002, 07:13 PM
There's where I'm undecided aobut C++. You can add a lot of structure, but then you get problems like that!