/* fileio1.cpp David Klick CIS 250 1/31/05 demonstration of simple text file I/O */ #include #include using std::cout; using std::endl; using std::ifstream; using std::ofstream; int main(void) { int n; float x = 0.0f; // open output file ofstream ofile("testfileio1.txt"); if (!ofile) { cout << "Error: couldn't open output file" << endl; return 1; } // write out 10 records of two space separated fields for (n=1; n<10; n++, x+=25) { ofile << n << " " << x << endl; } ofile.close(); // open input file ifstream ifile("testfileio1.txt"); if (!ifile) { cout << "Error: couldn't open input file" << endl; return 2; } // use priming read to read all records in file ifile >> n >> x; while (ifile) { cout << n << ", " << x << endl; ifile >> n >> x; } ifile.close(); return 0; }