Logo

Programming-Idioms

  • Fortran

Idiom #148 Read list of integers from stdin

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

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<_>, _>>();

result is a Result<Vec<i32>, ParseIntError>.
integer :: I,j,k ,l(3)
read(*,*) I, j, k, l
#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...