LearnFrenzy
Sign in Take a free test

Input/Output with cin and cout · Exercise 1 of 4

Input/Output with cin and cout Input/Output MCQ

  • 20 questions
  • Page 2 of 2
  • Answers explained
0Attempted
0Correct
0Wrong
Directions

Twenty multiple-choice questions on C++ streams: cin and cout, manipulators, getline, stream states, string streams, std::format and fast I/O. Pick an option to check your answer instantly.

Question 11 Medium

The user types abc for std::cin >> n; where n is an int. What happens (C++11 and later)?

A n gets the ASCII code of a
B failbit is set, n is set to 0, and "abc" remains in the input buffer
C The program throws an exception by default
D n keeps its old value and the input is discarded
Question page & discussion
Question 12 Medium

Why are std::cin.clear() and std::cin.ignore(…, '\n') called after a failed read?

A To clear the screen
B clear() resets the error flags so the stream works again; ignore() discards the bad characters still in the buffer
C To close the stream
D To flush cout
Question page & discussion
Question 13 Easy

When does the loop while (std::cin >> x) { … } stop?

A After 10 values
B When a read fails – at the end of input or when the data does not match x's type
C Never
D When x is 0
Question page & discussion
Question 14 Medium

What is the difference between std::cin.get(c) and std::cin >> c for a char c?

A None
B get(c) reads the next character even if it is whitespace; >> skips whitespace first
C get(c) reads a whole word
D >> reads only digits
Question page & discussion
Question 15 Easy

How do std::cerr and std::clog differ?

A cerr writes to a file
B Both write to standard error; cerr is unbuffered, clog is buffered
C clog is for input
D They are identical
Question page & discussion
Question 16 Easy

What is std::istringstream typically used for?

A Reading files
B Extracting values from a string with >> and getline, exactly like reading from cin
C Converting a number to a string only
D Network communication
Question page & discussion
Question 17 Medium

What does std::ios::sync_with_stdio(false); do?

A Turns off all output
B Stops synchronising C++ streams with C stdio, which makes cin/cout much faster – but they must not be mixed with printf/scanf afterwards
C Makes cin read from a file
D Enables multithreaded I/O
Question page & discussion
Question 18 Easy

Which header declares std::print and std::println?

A <iostream>
B <print>
C <format>
D <cstdio>
Question page & discussion
Question 19 Medium

How do you produce a literal { character with std::format?

A \{
B {{
C {'{'}
D It is impossible
Question page & discussion
Question 20 Medium

What does std::cin.peek() do?

A Reads and removes the next character
B Returns the next character without removing it from the stream
C Skips the next line
D Returns the number of characters waiting
Question page & discussion
Up next · Exercise 2Predict the Output20 questions

Ready to test your Programming?

Timed online tests with instant scores and explanations.

Search LearnFrenzy

Esc

Quick links