#includeusing namespace std; int main() { cout << "Hello world" << endl; // prints "Hello world" to console return 0; }
#includeIn this example, `ofstream` is a derived class of ostream, which is used to write to a file. The `<<` operator is used to insert data into the ofstream object. The file is opened using the constructor and closed using the `close()` method. Package library: C++ Standard Library (fstream header).using namespace std; int main() { ofstream outFile("myfile.txt"); outFile << "Hello world" << endl; // writes "Hello world" to file outFile.close(); return 0; }