Create A File and Display The Content of The File With Line Numbersin C++
Create A File and Display The Content of The File With Line Numbersin C++
#include <iostream>
#include <fstream>
int main() {
// Create and open a text file
std::ofstream outFile("example.txt");
if (outFile) {
outFile << "Hello, World!\n";
outFile << "This is a simple file example.\n";
outFile << "Enjoy coding in C++!\n";
outFile.close(); // Close the file after writing
}
return 0;
}
OUTPUT