home > 写経編 > 柴田望洋『明解C言語 入門編』 > 8. いろいろなプログラムを作ってみよう >

ForNext

Only Do What Only You Can Do

067. 標準入力からの入力を標準出力にコピーする

VBScript

JScript

Perl

更新日 : 2010.10.18
print while(<>);
L:\>perl lesson_08_067.pl
Hello,
Hello,
World!
World!
^Z

PHP

更新日 : 2010.11.03
<?php
$fp = fopen("php://stdin", "r");

while (!feof($fp))
{
    print(fgets($fp));
}

fclose($fp);
?>
L:\>php lesson_08_067.php
Hello,
Hello,
World!
World!
^Z

Python

更新日 : 2010.11.17
import sys

for line in iter(sys.stdin.readline, ""):
    sys.stdout.write(line)
N:\>python lesson_08_067.py
Hello,
Hello,
World!
World!
^Z

Ruby

更新日 : 2010.11.01
STDIN.each do |line|
  puts line
end

puts ""

puts $s while $s = STDIN.gets
L:\>ruby  l:\lesson_08_067.rb
Hello,
Hello,
World!
World!
^Z

Hello,
Hello,
World!
World!
^Z

PowerShell

Scala

F#

C

更新日 : 2010.10.08
#include <stdio.h>

int main(int argc, char* argv[])
{
    int ch;

    while ((ch = getchar()) != EOF)
        putchar(ch);

    return 0;
}
R:\>lesson067\Project1.exe
Hello,
Hello,
World!
World!
^Z

C++

C++Builder

VC++

C#

Java

更新日 : 2010.11.05
import java.util.Scanner;

class Lesson067 {
    public static void main(String[] args) {
        int[] cnt = new int[10];

        Scanner stdIn = new Scanner(System.in);

        while (stdIn.hasNext()) {
            System.out.println(stdIn.next());
        }
    }
}
L:\>java Lesson067
Hello,
Hello,
World!
World!
^Z

Objective-C

D

VB

VB.NET

Delphi

更新日 : 2010.09.24
program Project1;

{$APPTYPE CONSOLE}

uses
    SysUtils;

procedure main();
var
    s: String;
begin
    while (not Eof) do
    begin
        readln(s);
        writeln(s);
    end;
end;

begin
    main;
end.
S:\>lesson067\Project1.exe
Hello,
Hello,
World!
World!
^Z

Ada

PL/SQL

T-SQL

関数型

inserted by FC2 system