I've written my code for my homework, but when I execute it, rather than displaying the content of the file, it gets erased.
I can't figure out what I'm doing wrong.
Here's what I've written.
Code:#include <iostream> #include <fstream> #include <cstdlib> using namespace std; int main () { char next, advice; ifstream fin; ofstream fout; fin.open ("F:\\CS 2\\advice.txt"); fout.open ("F:\\CS 2\\advice.txt"); if (fin.fail()) { cout << "File failed to open.\n"; system ("pause"); exit (1); } if (fout.fail()) { cout << "File failed to open.\n"; system ("pause"); exit (1); } while (fin >> next) { fin.get(next); cout << next; } cout << "\n\n" << "Input your own advice.\n"; cin >> advice; while (! cin >> '\n') { cin.get(advice); fout << advice; } fin.close ( ); fout.close ( ); system ("pause>nul"); }



LinkBack URL
About LinkBacks


