1#include <iostream>
2#include <fstream>
3using namespace std;
4
5int main() {
6 // Create and open a text file
7 ofstream MyFile("filename.txt");
8
9 // Write to the file
10 MyFile << "Files can be tricky, but it is fun enough!";
11
12 // Close the file
13 MyFile.close();
14
1// using ofstream constructors.
2#include <iostream>
3#include <fstream>
4
5std::ofstream outfile ("test.txt");
6
7outfile << "my text here!" << std::endl;
8
9outfile.close();
10