// pgm16 OUTPUT FILES // need to store output of files permanently // 9/28/16 #include // include fstream to be able to use files #include #include using namespace std; int main() { string filename; cout << "What is the name of your output file?"; cin >> filename; // this defines an output file stream object ofstream myofile; // similar to cout, its an identifier that you make up // when a file is open for writing, it gets ERASED // if you are using a mac, use a forward slash / between // levels of the pathname myofile.open("C:\\Users\\Staff\\Documents\\Sokol\\Fall 2016\\output3.txt"); // myofile.open(filename.c_str()); // escape sequences myofile << "Hello world." << endl; // write all even numbers from 2 to 100 to a file. for (int i=2; i<=100; i+=2) myofile << i << endl; myofile << "This is the last line of the file!!"; myofile.close(); return 0; }