/* This program shows you how to do file I/O with C++. */ #include // include fstream declaration #include #include // include standard library #include using namespace std; int main() { size_t const MAX = 128; vector a(128, 2.0E0); // a vector, assign all elements // the value of 2.0E0 ofstream dest("matrix.dat"); // ofstream -> output file if (!dest) { // check if matrix.dat opened cerr << "Cannot open file matrix.dat" << endl; exit(1); // if not, exit } for (size_t i = 0; i != MAX; ++i) dest << a[i] << ' '; dest << endl; // end final record dest.close(); // close matrix.dat }