Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!

Idiom #148 Read list of integers from stdin

Read a list of integer numbers from the standard input, until EOF.

process.stdin.on('data', processLine)

function processLine (line) {
  const string = line + ''
  console.log(string)
}
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))))
})
#include <vector>
#include <iostream>

using namespace std;
vector<int> v;
for(int t;;){
	cin >> t;
	if(cin.eof())
		break;
	v.push_back(t);
}

there must be 2 semicolon in for loop even it is empty

New implementation...