Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #include <fstream> // fStream object
  2. #include <iostream> // std::cout
  3.  
  4. int main(int argc, char** argv)
  5. {
  6. // Our file stream, opening a file called log.txt and writing over anything already there
  7. std::fstream fileObject("log.txt", std::ios::out | std::ios::trunc);
  8.  
  9. // Verify that we opened the file successfully
  10. if (!fileObject.is_open())
  11. throw "File failed to open!";
  12.  
  13. // Write to the file, just like we do with the console
  14. fileObject << "Files are fun!" << std::endl;
  15. fileObject << "This is just like printing to the console!" << std::endl;
  16.  
  17. // Close the file, allowing for reuse of the object
  18. fileObject.close();
  19. return 0;
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement