C++ Program to write text to a file, Here we are using the output stream class ofstream to write the data to the file.
#include <iostream> #include <fstream> using namespace std; int main () { ofstream file; string content = "Hello this is CodeCry"; file.open ("sample.txt"); file << content; file.close(); return 0; }
Hello this is CodeCry
While compiling this Program, the following text will be written to the file
Hello this is CodeCry
Comments :