C++ examples for File Stream:File Operation
Using Code to Open a File and Read It Back In
#include <iostream> #include <fstream> #include <string> using namespace std; void ReadFile(string filename) { ifstream infile(filename.c_str());// w ww . j av a 2 s. c o m int count; int i; int num; cout << "File: " << filename << endl; infile >> count; cout << "This file has " << count << " items." << endl; for (i=0; i<count; i++) { infile >> num; cout << num << endl; } infile.close(); } int main() { ReadFile("../nums1.txt"); ReadFile("../nums2.txt"); return 0; }