fork download
  1. #include <iostream>
  2. #include <fstream>
  3.  
  4. using namespace std;
  5.  
  6. const unsigned bufferSize = 125;
  7. int main() {
  8. const char fileName[] = "/myStory.txt";
  9. fstream myfile;
  10. cout << "Processing... Opening file name as: " << fileName << "... Purpose: Reading and Writing File." << endl;
  11. myfile.open(fileName, ios::out | ios::in | ios::trunc);
  12. myfile << "I love to code" << endl;
  13. myfile << "I really love to code in C++" << endl;
  14. myfile << "Coding makes me very happy" << endl;
  15. myfile << "Give me more code to write" << endl;
  16.  
  17. cout <<"Input Verified. Reading File " << fileName << "... Please wait." << endl;
  18. char outBuffer[bufferSize] = {125};
  19. cout << "Input Data from " << fileName << " is:" << endl;
  20. while(myfile.getline(outBuffer, bufferSize))
  21. {
  22. cout << outBuffer << endl;
  23. }
  24. myfile.close();
  25. return 0;
  26. }
Success #stdin #stdout 0s 16064KB
stdin
Standard input is empty
stdout
Processing... Opening file name as: /myStory.txt... Purpose: Reading and Writing File.
Input Verified. Reading File /myStory.txt... Please wait.
Input Data from /myStory.txt is: