My Report

C++ File and Stream Test – 1


Correct Answer: 2 points | Wrong: -1 point
Grades: A* (100% score) | A (80%-99%) | B (60%-80%) | C (40%-60%) | D (0%-40%)
advertisement

1. Pick out the correct objects about the instantiation of output stream.

2. What is meant by ofstream in c++?

3. What will be the output of the following C++ code?

  
    #include <iostream>
    using namespace std;
    int main ()
    {
        int n;
        n = -77;
        cout.width(4); 
        cout << internal << n << endl;
        return 0;
    }

4. What will be the output of the following C++ code?

  
    #include <iostream>
    using namespace std;
    int main () 
    {
        int n; 
        n = 43;
        cout << hex << n << endl;
        return 0;
    }

5. What must be specified when we construct an object of class ostream?

6. How many types of output stream classes are there in c++?

7. How many groups of output of operation are there in c++?

8. What is the output of this C++ program in the "test.txt" file?

    #include <fstream>
    using namespace std;
    int main ()
    {
        long pos;
        ofstream outfile;
        outfile.open ("test.txt");
        outfile.write ("This is an apple",16);
        pos = outfile.tellp();
        outfile.seekp (pos - 7);
        outfile.write (" sam", 4);
        outfile.close();
        return 0;
    }

9. What will be the output of the following C++ code?

  
    #include <iostream>
    #include <locale>
    using namespace std;
    int main()
    {
        locale mylocale("");
        cout.imbue( mylocale );
        cout << (double) 3.14159 << endl;
        return 0;
    }

10. What will be the output of the following C++ code?

  
    #include <iostream>
    using namespace std;
    int main () 
    {
        char str[] = "Steve jobs";
        int val = 65;
        char ch = 'A';
        cout.width (5);
        cout << right;
        cout << val << endl;
        return 0;
    }

 

Start practicing “1000 MCQs on C++”, and once you are ready, you can take tests on all topics by attempting our “C++ Test Series”.

Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.