c++ create new file code example
Example 1: c++ files
#include <iostream>
#include <fstream>
using namespace std;
int main () {
ofstream myfile;
myfile.open ("example.txt");
myfile << "Writing this to a file.\n";
myfile.close();
return 0;
}
Example 2: create new file c++
#include <iostream>
#include <fstream>
using namespace std;
int main() {
ofstream MyFile("filename.txt");
MyFile << "Files can be tricky, but it is fun enough!";
MyFile.close();
Example 3: create file c++
#include <iostream>
#include <fstream>
std::ofstream outfile ("test.txt");
outfile << "my text here!" << std::endl;
outfile.close();