c++ fstream create if not exists

#include <iostream>
#include <fstream>

int main() {
    std::ofstream file("example.txt", std::ios::out | std::ios::app);

    if (!file.is_open()) {
        std::cerr << "Error opening the file." << std::endl;
        return 1;
    }

    // Write data to the file
    file << "Hello, World!" << std::endl;

    // Close the file
    file.close();

    return 0;
}