Files and Streams


  1. By seeing which operator thus this program stops getting the input?
    #include <iostream>
    #include <fstream>
    using namespace std;
    int main ()
    {
    char ch;
    streambuf * pbuf;
    ofstream os ("Example.txt");
    pbuf = os.rdbuf();
    do {
    ch = cin.get();
    pbuf -> sputc(ch);
    } while (ch != '.');
    os.close();
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: B

    This program will stop getting the input, When it occurs the dot(.) operator.


  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. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

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



  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main ()
    {
    int num1 = 150;
    double num2 = 6.251;
    cout << num1;
    cout << " ";
    cout << num2 << " " << num1 * num2;
    endl (cout);
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: A

    In this program, We are printing the given value and manipulating the given value by using endl.


  1. What is the output of this program?
    #include <iostream>
    using namespace std;
    int main ()
    {
    char First_ch, Second_ch, Third_ch;
    cout << "Enter any word or number: ";
    First_ch = cin.get();
    cin.sync();
    Second_ch = cin.get();
    cin.sync();
    Third_ch = cin.get();
    cout << First_ch << endl;
    cout << Second_ch << endl;
    cout << Third_ch << endl;
    return 0;
    }











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: D

    In this program, We are using the sync function to return the first three letters of the entered word.



  1. Which member function is used to determine whether the stream object is currently associated with a file?











  1. View Hint View Answer Discuss in Forum

    NA

    Correct Option: C

    The member function is_open can be used to determine whether the stream object is currently associated with a file.