Logo

Programming-Idioms

Read one line into the string line.

Explain what happens if EOF is reached.
New 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
with Ada.Text_IO;
Line : constant String := Ada.Text_IO.Get_Line;
#include <iostream>
#include <string>
int main() {
    for (std::string line; std::getline(std::cin, line);) {
        std::cout << line << std::endl;
    }
    return 0;
}
using System;
var line = Console.ReadLine();
import "bufio"
import "os"
s := bufio.NewScanner(os.Stdin)
if ok := s.Scan(); !ok {
	log.Fatal(s.Err())
}
line := s.Text()
import java.util.Scanner;
String line = null;
Scanner in = new Scanner(System.in);
if(in.hasNextLine())
    line = in.nextLine();
import java.util.Scanner;
Scanner s = new Scanner(System.in);
String line = s.nextLine();
s.close();
readln(line);
$line = <STDIN>;
import sys
line = sys.stdin.readline()
line = gets
let mut buffer = String::new();
let mut stdin = io::stdin();
stdin.read_line(&mut buffer).unwrap();