Home » C++ Programming » Files and Streams » Question
  1. What is the output of this program?
    #include <iostream>
    #include <fstream>
    using namespace std;
    int main ()
    {
    ofstream outfile ("Sample.txt");
    for (int num = 0; num < 50; num++)
    {
    outfile << num;
    outfile.flush();
    }
    cout << "Done successfully";
    outfile.close();
    return 0;
    }
    1. compilation Error
    2. Runtime Error
    3. Garbage value
    4. Done successfully
    5. None of these
Correct Option: D

In this program, We are using the flush function to update the contents in a file.



Your comments will be displayed only after manual approval.