Complete the code to include the header needed for file output.
#include [1] int main() { return 0; }
The
Complete the code to create an ofstream object named 'file' that opens 'output.txt'.
std::[1] file("output.txt");
ofstream is used to write to files.
Fix the error in the code to write 'Hello, file!' to the file.
std::ofstream file("output.txt"); file [1] "Hello, file!"; file.close();
The insertion operator << is used to write data to the file stream.
Fill both blanks to check if the file was opened successfully and print a message.
std::ofstream file("output.txt"); if (file.[1]()) { std::cout << "File opened successfully." << std::endl; } else { std::cout << "Failed to open file." << std::endl; }
The is_open() function checks if the file stream is open.
Fill all three blanks to write multiple lines to a file using a loop.
std::ofstream file("output.txt"); for (int [1] = 1; i <= 3; [2]) { file [3] "Line " << i << std::endl; } file.close();
Use 'i' as the loop variable, increment it with ++i, and write to file using << operator.
