#include#include using namespace std; int main () { ofstream myfile; myfile.open ("example.txt"); myfile << "Writing this to a file.\n"; myfile.close(); return 0; }
#includeint main() { FILE* filePointer = fopen("example.txt", "w"); fprintf(filePointer, "Hello, World!"); fclose(filePointer); return 0; }
#includeIn this example, we use the Boost C++ Libraries to manipulate files and directories on the file system. The path() function is used to create a filesystem path object to refer to the "example.txt" file. We then use an ofstream object to open the file for writing and write "Hello, World!" to the file. Finally, we close() the file using the close() function of the ofstream object.using namespace boost::filesystem; int main() { path filePath("example.txt"); ofstream file(filePath.string().c_str()); file << "Hello, World!"; file.close(); return 0; }