Having trouble with file input...

This is a discussion on Having trouble with file input... within the C++ Programming forums, part of the General Programming Boards category; Well folks, here's the deal: this script was working perfectly fine, peachy, whatever, but then I apparently did something to ...

  1. #1
    Registered User
    Join Date
    Dec 2002
    Posts
    3

    Unhappy Having trouble with file input...

    Well folks, here's the deal: this script was working perfectly fine, peachy, whatever, but then I apparently did something to screw it up. Danged if I know what it was. *scratches head*

    Anyways..

    [old]Note: readcon is a private ofstream of config, and writecon is a private ifstream[/old]
    [edit]Note: readcon is a private ifstream of config, and writecon is a private ofstream[/edit]
    Code:
    config::loadconf( void ) {
    	readcon.open("config.blh");
    	if (!readcon) {cout << "Drat."<<endl;}
    	readcon >> temp;
    	if(!strcmp(temp,"JEPD")) {
    		readcon >> ver;
    	} else {
    		readcon.close();
    		newConf();
    	}
                    //Other stuff here, but wasn't running anyways, so doesn't matter.
    	readcon.close();
    	return ver;
    }
    
    int main ( void ) { //t'was more to my main, as well, but this is the stuff related to my prob...
    	config c;
    	c.loadconf();
    	return 0;	
    }
    Now... inside config.blh is simple, plain ascii text of

    JEPD
    1
    [DBP]
    [ENDDBP]
    And, by the way, I didn't put that there, it was written with:
    Code:
    config::newConf( void ) {
    	writecon.open("config.blh",ios::trunc);
    	writecon << "JEPD\n1\n[DBP]\n[ENDDBP]";
    	writecon.close();
    	cout << "Created new config file.\n";
    	readcon.open("config.blh");
    	return 0;
    	
    }
    So, what happens is that it keeps running newConf...(and outputting "Drat").
    It never successfully opens the file to read from.

    I assume it's some easy fix that I'm missing, but I can't tell you what it is. Hopefully one of you can, I'll be greatfull for the help.

    If you need any additional info to help me with this, please ask, because I'm pretty screwed, right now.
    Last edited by Xaviar; 12-10-2002 at 12:59 PM.

  2. #2
    Registered User
    Join Date
    Apr 2002
    Posts
    80
    I think you mean that readcon is an ifstream, and writecon is an ofstream.

  3. #3
    Registered User
    Join Date
    Dec 2002
    Posts
    3
    And you would be correct X_X

    Thanks..

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File transfer- the file sometimes not full transferred
    By shu_fei86 in forum C# Programming
    Replies: 13
    Last Post: 03-13-2009, 01:44 PM
  2. fscanf in different functions for the same file
    By bchan90 in forum C Programming
    Replies: 5
    Last Post: 12-03-2008, 09:31 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 09:39 AM
  4. simulate Grep command in Unix using C
    By laxmi in forum C Programming
    Replies: 6
    Last Post: 05-10-2002, 05:10 PM
  5. Need a suggestion on a school project..
    By Screwz Luse in forum C Programming
    Replies: 5
    Last Post: 11-27-2001, 02:58 AM

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