#include#include int main() { std::ifstream infile("example.txt"); std::string line; while (std::getline(infile, line)) { std::cout << line << std::endl; } return 0; }
#includeThis code creates a new file named "example.txt" and writes the string "Hello, world!" to it. Note that if the file already exists, its contents will be overwritten. The cpp fstream library is part of the standard C++ library.#include int main() { std::ofstream outfile("example.txt"); outfile << "Hello, world!" << std::endl; return 0; }