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. myfile.seekg(125, ios::beg);
  19. char outBuffer[bufferSize] = {125};
  20. cout << "Input Data from " << fileName << " is:" << endl;
  21. while(myfile.getline(outBuffer, bufferSize))
  22. {
  23. cout << outBuffer << endl;
  24. }
  25. myfile.close();
  26. return 0;
  27. }
Success #stdin #stdout 0s 15240KB
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: