C ProgrammingDiscussion
Seekg() question...

ThePornAmbitionFeb 5, 11:00pm
I am foolin' around with some code that compares two txt files. The format of the txt files is as follows:

23 45 52 12 1
14 4 34 21 22
20 21 23 24 3

One line of five numbers in one txt file is compared to all of the lines of five numbers in the other txt file until all lines have been compared. Can you guys spot the problem? The seekg( o , ios::beg ) statement doesn't seem to work! Ask me any questions. This isn't for school or work just personal study. Also, I have been all over Google. Here is some code that is similar to mine:




#include
#include
#include

short a = 0 , b = 0 , c = 0 , d = 0 , e = 0 , d1 = 0 , d2 = 0 , d3 = 0 , d4 = 0 , d5 = 0;

ifstream inFile1( "Example.txt" , ios::in );
ifstream inFile2( "Example.txt" , ios::in );

if( inFile1.fail( ) || inFile2.fail( ) ) cerr << "Error.\n";

while( inFile1 >> d1 >> d2 >> d3 >> d4 >> d5 ){

while( inFile2 >> a >> b >> c >> d >> e ){

// Do stuff in here...

}

inFile2.seekg( 0 , ios::beg );

}

inFile1.close();
inFile2.close();


**EDIT** Ok, I just found the asnwer on goolge! I have to have a inFile.clear(); before my seeekg statement!


Seekg() question...

You need to Sign-up for StumbleUpon to post to this forum