Message-Id: <199804280525.BAA00183@mail.cgocable.net> From: "Glen L. Bowes" To: djgpp AT delorie DOT com Date: Tue, 28 Apr 1998 01:25:17 +0000 MIME-Version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7BIT Subject: ifstream & repositioning file pointers Reply-to: bowes AT cgocable DOT net Precedence: bulk Hi, Would someone be kind enough to explain how to reposition a file file pointer in C++ when using ifstream? I'm trying to write a class to deal with .ini type files as below (very incomlete!!): #include #include const int LINE_SIZE = 100; class fio { public: fio(char* filename); int getNumSec() {return secCount;} void findSec(char*); void findVar(char*, char*); private: ifstream infile; int secCount; }; fio::fio(char *filename) { infile.open(filename); if(!infile) { cerr << "Could not open " << filename << ", aborting... "; exit(1); } secCount = 0; char buffer[LINE_SIZE]; while(infile) { infile.getline(buffer, LINE_SIZE); if(buffer[0] == '[') secCount++; } } void fio::findSec(char* secName) { char buffer[LINE_SIZE]; bool found = false; while(infile && found == false) // <-- Problem here - file pointer { infile.getline(buffer, LINE_SIZE); int size_left = strlen(secName) - 2; if(buffer[0] == '[') { int count; for(count = 0; count < size_left; count++) { if(!(buffer[count] == secName[count])) found = false; else found = true; } } } if(found == true) cout << endl << "found \"" << secName << " \""; else cout << endl << "\"" << secName << "\" not found or bad code"; } void fio::findVar(char* secName, char* varName) { fio::findSec(secName); char buffer[LINE_SIZE]; while(infile) { infile.getline(buffer, LINE_SIZE); if(buffer[0] == '[') { cout << "Variable " << varName << " not found in this section " << "aborting "; exit(1); } } } void main() { fio test("fiotest.ini"); cout << "Number of sections: " << test.getNumSec(); test.findSec("test section"); // test.findVar("test section", "test1"); } Many many thanks in advance! Glen L. Bowes