Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- #include <string>
- #include <chrono>
- using namespace std;
- int main()
- {
- // create a time stamp string
- auto now = chrono::system_clock::now();
- time_t time = chrono::system_clock::to_time_t(now);
- string timestamp = to_string(time);
- // create a file stream object and open a file with a timestamp in its name
- ofstream outfile("x64/example_" + timestamp + ".txt");
- // check if the file was opened successfully
- if ( !(outfile.is_open()) )
- {
- cout << "Failed to open the file." << "\n";
- return 1;
- }
- // write some text to the file
- outfile << "This is an example text file created with C++." << "\n";
- // close the file stream
- outfile.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement