#includeint main() { std::ofstream outfile("example.txt"); outfile << "Hello world"; outfile.close(); return 0; }
#includeIn this example code, the ifstream class is used to open a file named example.txt and read its contents. The contents are then printed to the console using std::cout. Again, the fstream package library is included in the standard C++ library. Overall, the std fstream library is a very useful tool for file input and output in C++. It provides an easy-to-use interface for reading and writing files, and is included in the standard C++ library.#include int main() { std::ifstream infile("example.txt"); std::string line; while (std::getline(infile, line)) { std::cout << line << '\n'; } infile.close(); return 0; }