LearnFrenzy
Sign in Take a free test

Input/Output with cin and cout · Find the Error · Question 1

Error: cin used with << instead of >> Answer, explanation & discussion

  • Find the error
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 1 Back to Exercise

The program below does not compile. Which statement correctly describes the problem?

main.cpp
#include <iostream>

int main() {
    int n;
    std::cin << n;
    std::cout << n * 2 << '\n';
    return 0;
}
  • A n must be initialised
  • B cin is an input stream and uses the extraction operator >>; << is only defined for output streams Correct
  • C cout cannot multiply
  • D cin needs parentheses
Correct Answer: Option B

Remember the arrows point where the data goes: cin >> n moves data into n, cout << n moves it out to the screen.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links