Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <fstream> // fStream object
- #include <iostream> // std::cout
- int main(int argc, char** argv)
- {
- // Our file stream, opening a file called log.txt and writing over anything already there
- std::fstream fileObject("log.txt", std::ios::out | std::ios::trunc);
- // Verify that we opened the file successfully
- if (!fileObject.is_open())
- throw "File failed to open!";
- // Write to the file, just like we do with the console
- fileObject << "Files are fun!" << std::endl;
- fileObject << "This is just like printing to the console!" << std::endl;
- // Close the file, allowing for reuse of the object
- fileObject.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement