Skip to main content
CodeLab logoCodeLab

2026-10-07 · Guide

Stdin in an online compiler: how piped input works

Programs that read input need stdin, not typing at a terminal. Learn how the stdin panel maps to input(), Scanner, cin and readLine.

Stdin is a file, not a conversation

Online runtimes cannot pause and ask you to type mid-run the way a terminal does. Instead, everything your program will read must be pre-filled in the stdin panel before you press Run.

Think of stdin as a text file your program reads from top to bottom: the first input() or Scanner call takes the first line, the next call takes the second, and so on.

Map lines to reads

Python input() reads one line; Java Scanner.nextLine() reads one line; C++ getline(cin, s) reads one line. Count your reads and provide exactly that many lines.

Running out of lines raises EOFError in Python or blocks with NoSuchElementException in Java. Extra lines are simply ignored, so err on the side of complete input while learning.

Debug stdin failures fast

Echo the input back as the first output line while debugging, so you can confirm what the program actually received. Then remove the echo before submitting.

For multi-case algorithm practice, put the case count on line one (e.g. 3) followed by one case per line — the standard competitive-programming layout.

FAQ

Where is the stdin panel?

Inside the embedded editor, next to the code and output panes. Fill it before pressing Run — edits after the run starts do not apply retroactively.

Why does my program hang waiting for input?

It is almost always an empty or short stdin panel. Provide every line the program reads, in order, then run again.