Logo

Programming-Idioms

Read a list of integer numbers from the standard input, until EOF.
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
#include <vector>
#include <iostream>

using namespace std;
vector<int> v;
for(int t;;){
	cin >> t;
	if(cin.eof())
		break;
	v.push_back(t);
}
string input = Console.ReadLine();
string[] intlist = input.Split(new char[] {',', ' '});
	
foreach(string item in intlist)
{
  Console.WriteLine(Convert.ToInt32(item));
}
import std.stdio;
import std.conv : to;
import std.algorithm.iteration : map;
auto list = stdin.byLine.map!(a => a.to!int);
integer :: I,j,k ,l(3)
read(*,*) I, j, k, l
import (
	"bufio"
	"os"
	"strconv"
)
var ints []int
s := bufio.NewScanner(os.Stdin)
s.Split(bufio.ScanWords)
for s.Scan() {
	i, err := strconv.Atoi(s.Text())
	if err == nil {
		ints = append(ints, i)
	}
}
if err := s.Err(); err != nil {
	return err
}
read <$> getLine :: IO [Integer]

-- reading space separated list of ints
map read . words <$> getLine :: IO [Int]
const ints = await new Promise(resolve => {
  let string = ''
  process.stdin
    .on('data', data => string += data.toString())
    .on('close', () => resolve(string.split('\n').map(line => Number.parseInt(line))))
})
process.stdin.on('data', processLine)

function processLine (line) {
  const string = line + ''
  console.log(string)
}
import java.util.List;
import java.util.Scanner;
import java.util.stream.Collectors;
import java.util.stream.IntStream;
Scanner scanner = new Scanner(System.in);
List<Integer> list = IntStream.generate(scanner::nextInt)
                .takeWhile((i) -> scanner.hasNextInt())
                .boxed()
                .collect(Collectors.toList());
(read)
fgl
type
  TFloatList = specialize TFPGList<Double>;
var
  List: TFloatList;
  D: Double;

begin
  List := TFloatList.Create;
  while not Eof do
  begin
    Read(D);
    List.Add(D);
  end;
  List.Free;
end.
@x = map {chomp; $_} <>;
numbers = [int(x) for x in input().split()]
list(map(int, input().split())
STDIN.read.split.map(&:to_i)
use std::{
    io::{self, Read},
    str::FromStr,
}
let mut string = String::new();
io::stdin().read_to_string(&mut string)?;
let result = string
    .lines()
    .map(i32::from_str)
    .collect::<Result<Vec<_>, _>>();