C++ I/O Streams (cin, cout)

Unit 1 Β· Topic 1.6⏱ 8 min read❓ 5 MCQs

Introduction

C++ uses stream objects cin (standard input) and cout (standard output) with >> (extraction) and << (insertion) operators.

Definition

Stream: A flow of bytes. cin/cout are predefined objects in <iostream>.

Code Example

#include <iostream>
using namespace std;
int main(){
    int x; cout<<"Enter: "; cin>>x;
    cout<<"You entered: "<<x<<endl;
    return 0;
}

Important Questions

Short Questions

  1. What is cin?
  2. What is cout?
  3. Difference between >> and <<?
  4. What is endl?

Long Questions

  1. Explain stream I/O in C++.
  2. Discuss cascading of I/O operators.

MCQ Practice

1. cin is defined in:

  • <iostream>
  • <stdio.h>
  • <conio.h>
  • <stdlib.h>
Answer: <iostream>.

2. Extraction operator is:

  • >>
  • <<
  • ::
  • .*
Answer: >>.

3. Insertion operator is:

  • <<
  • >>
  • ::
  • ->
Answer: <<.

4. endl does:

  • Newline + flush
  • Only newline
  • Nothing
  • Clears stream
Answer: newline + flush.

5. Cascading means:

  • Multiple <</>> in one statement
  • Looping
  • Recursion
  • Inheritance
Answer: multiple operators.

Quick Revision

  • cin/cout streams.
  • >> extract, << insert.
  • endl newline+flush.