Logo

Programming-Idioms

Read one line into the string line.

Explain what happens if EOF is reached.
Implementation
Go

Implementation edit is for fixing errors and enhancing with metadata. Please do not replace the code below with a different implementation.

Instead of changing the code of the snippet, consider creating another Go implementation.

Be concise.

Be useful.

All contributions dictatorially edited by webmasters to match personal tastes.

Please do not paste any copyright violating material.

Please try to avoid dependencies to third-party libraries and frameworks.

Other implementations
import sys
line = sys.stdin.readline()
line = gets
readln(line);
#include <iostream>
#include <string>
int main() {
    for (std::string line; std::getline(std::cin, line);) {
        std::cout << line << std::endl;
    }
    return 0;
}
let mut buffer = String::new();
let mut stdin = io::stdin();
stdin.read_line(&mut buffer).unwrap();
with Ada.Text_IO;
Line : constant String := Ada.Text_IO.Get_Line;
import java.util.Scanner;
String line = null;
Scanner in = new Scanner(System.in);
if(in.hasNextLine())
    line = in.nextLine();
$line = <STDIN>;
using System;
var line = Console.ReadLine();
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
InputStreamReader inputStreamReader = new InputStreamReader(System.in);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);

String line = null;
try {
	line = bufferedReader.readLine();
} catch (IOException exception) {
	exception.printStackTrace();
} finally {
	try {
		bufferedReader.close();
	} catch(IOException exception) {
		exception.printStackTrace();
	}
}