My Report

C++ File and Stream Test – 2


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. Which operator is used for input stream?

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

  
    #include <iostream>
    using namespace std;
    int main ()
    {
        int i;
        cout << "Please enter an integer value: ";
        cin >> i + 4;
        return 0;
    }

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

  
    #include <iostream>
    #include <string>
    #include <sstream>
    using namespace std;
    int main ()
    {
        string mystr;
        float price = 0;
        int quantity = 0;
        cout << "Enter price: ";
        getline (cin, mystr);
        stringstream(mystr) >> price;
        cout << "Enter quantity: ";
        getline (cin, mystr);
        stringstream(mystr) >> quantity;
        cout << "Total price: " << price * quantity << endl;
        return 0;
    }

4. Which is used to get the input during runtime?

5. When will the cin can start processing of input?

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

  
    #include <iostream>
    using namespace std;
    int main( )
    {
        char line[100];
        cin.getline( line, 100, 't' );
        cout << line;
        return 0;
    }

7. What can be used to input a string with blank space?

8. Where does a cin stops it extraction of data?

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

  
    #include <iostream>
    #include <ios>
    #include <istream>
    #include <limits>
    using namespace std;
    template <typename CharT>
    void ignore_line ( basic_istream<CharT>& in )
    {
        in.ignore ( numeric_limits<streamsize> :: max(), in.widen ( '\n' ) );
    }
    int main()
    {
        cout << "First input: ";
        cin.get();
        cout << "Clearing cin.\n";
        cin.clear();
        ignore_line ( cin );
        cout << "All done.\n";
    }

10. How many parameters are there in getline function?


 

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.