create new file c++ code example
Example 1: create new file c++
#include
#include
using namespace std;
int main() {
// Create and open a text file
ofstream MyFile("filename.txt");
// Write to the file
MyFile << "Files can be tricky, but it is fun enough!";
// Close the file
MyFile.close();
Example 2: create file c++
// using ofstream constructors.
#include
#include
std::ofstream outfile ("test.txt");
outfile << "my text here!" << std::endl;
outfile.close();