Logo

Programming-Idioms

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

Idiom #148 Read list of integers from stdin

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

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.

The fgl unit holds the prototype for generic listst.
#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...