Logo

Programming-Idioms

Read all the lines (until EOF) into the list of strings lines.
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;
with Ada.Containers.Indefinite_Vectors;
declare
   package String_Vectors is new
      Ada.Containers.Indefinite_Vectors
         (Index_Type => Positive, Element_Type => String);
   use String_Vectors, Ada.Text_IO;
   Lines : Vector;
begin
   while not End_Of_File loop
      Lines.Append (Get_Line);
   end loop;
end;
import "bufio"
import "os"
var lines []string
s := bufio.NewScanner(os.Stdin)
for s.Scan() {
	line := s.Text()
	lines = append(lines, line)
}
if err := s.Err(); err != nil {
	log.Fatal(err)
}
import java.util.List;
import java.util.ArrayList;
import java.util.Scanner;
List<String> lines = new ArrayList<>();
Scanner in = new Scanner(System.in);
while(in.hasNextLine())
    lines.add(in.nextLine());
uses classes;
while not EOF do
begin
  readln(s);
  lines.Add(s);
end;
@lines = <STDIN>;
import sys
lines = sys.stdin.readlines()
lines = readlines
use std::io::prelude::*;
let lines = std::io::stdin().lock().lines().map(|x| x.unwrap()).collect::<Vec<String>>();