Home » C++ Programming » Files and Streams » Question
  1. What is the output of this program in text files?
    #include <iostream>
    int main ()
    {
    char buff[BUFSIZ];
    FILE *ptr1, *ptr2;
    ptr1 = fopen ("FirstFile.txt", "w");
    ptr2 = fopen ("SecondFile.txt", "a");
    setbuf ( ptr1 , buff );
    fputs ("Buffered stream", ptr1);
    fflush (ptr1);
    setbuf ( ptr2 , NULL );
    fputs ("Unbuffered stream", ptr2);
    fclose (ptr1);
    fclose (ptr2);
    return 0;
    }
    1. Compilation Error
    2. Buffered stream
    3. Unbuffered stream
    4. Buffered & Unbuffered stream
    5. None of these
Correct Option: D

In this program, the fopen will create the file and send the text to both of the files.



Your comments will be displayed only after manual approval.