Strange ifstream problem...

This is a discussion on Strange ifstream problem... within the A Brief History of Cprogramming.com forums, part of the Community Boards category; I have the following code: Code: #include <iostream> #include <fstream> using namespace std; char academics[1000000]; char sports[1000000]; char extra[1000000]; char ...

  1. #1
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001

    Strange ifstream problem...

    I have the following code:
    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.portfolio");
    	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.portfolio");
    	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.portfolio");
    	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?
    PHP and XML
    Let's talk about SAX

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    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:
    Code:
    if( !sfin.is_open() )

  3. #3
    PC Fixer-Upper Waldo2k2's Avatar
    Join Date
    May 2002
    Posts
    2,001
    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.
    PHP and XML
    Let's talk about SAX

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    There's where I'm undecided aobut C++. You can add a lot of structure, but then you get problems like that!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem with ifstream
    By peste19 in forum C++ Programming
    Replies: 10
    Last Post: 02-25-2009, 10:15 AM
  2. Strange problem with GETLINE
    By wco5002 in forum C++ Programming
    Replies: 13
    Last Post: 07-07-2008, 09:57 AM
  3. Strange problem
    By G4B3 in forum C Programming
    Replies: 6
    Last Post: 05-14-2008, 02:07 PM
  4. Strange problem with classes in header files
    By samGwilliam in forum C++ Programming
    Replies: 2
    Last Post: 02-29-2008, 03:55 AM
  5. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21