Home › Forums › C Programming › Read in from a file with specific syntax … › Reply To: Read in from a file with specific syntax …
December 13, 2007 at 2:42 pm
#3292
Humayan
Participant
Heres an old program that I have that reads an int then a float on each line:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | /****************************************************************<br /> * File Name : cgt.cpp<br /> * Date : April,18,2006<br /> * Comments : new project<br /> * Program Shell Generated At: 10:33:48<br /> =-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/<br /> #include <br /> #include <br /> <br /> int main()<br /> {<br /> ifstream inputFile ( "c:\programs\CSC2133N.TXT" );<br /> if ( inputFile.fail() ) //check if file opened<br /> {<br /> cout << "File Did Not Open!" << endl;<br /> return 1;<br /> }<br /> <br /> int i;<br /> double d; //use better names here!!!!!<br /> <br /> inputFile >> i;<br /> while ( ! inputFile.eof() )<br /> {<br /> inputFile >> d;<br /> cout << i << " " << d << endl;<br /> inputFile >> i;<br /> }<br /> inputFile.close();<br /> return 0;<br /> } |