Home Forums C Programming Read in from a file with specific syntax … Reply To: Read in from a file with specific syntax …

#3292
Humayan
Participant

Heres an old program that I have that reads an int then a float on each line:
 

/****************************************************************
* File Name : cgt.cpp
* Date : April,18,2006
* Comments : new project
* Program Shell Generated At: 10:33:48
=-=-=-=-=-=-=-=--=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
#include
#include

int main()
{
 ifstream inputFile ( "c:\programs\CSC2133N.TXT" );
 if ( inputFile.fail() ) //check if file opened
 {
  cout << "File Did Not Open!" << endl;
  return 1;
 }
 
 int i;
 double d; //use better names here!!!!!
 
 inputFile >> i;
 while ( ! inputFile.eof() )
 {
  inputFile >> d;
  cout << i << " " << d << endl;
  inputFile >> i;
 }
 inputFile.close();
 return 0;
}