Number / 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
$ ./test input >abc 'abc' $
#include <stdio.h> #define BUFFER_SIZE 16 int main() { char s[BUFFER_SIZE+1] = ""; int i, c; printf("input >"); /* バッファオーバーフロー回避 X gets(s); 改行も取ってきてしまう X fgets(s, BUFFER_SIZE, stdin); */ /* 改行でもEOFでも文字列の終端 */ for (i = 0; i < BUFFER_SIZE; i++) { c = getchar(); if (c == EOF || c == '\r' || c == '\n') break; s[i] = c; } printf("'%s'\n",s); return 0; }
#include <iostream> #include <string> int main() { std::string s = ""; std::cout << "input >"; std::cin >> s; std::cout << "'" << s << "'" << std::endl; return 0; }
import java.io.*; class Main { public static void main(String[] args) { try { System.out.print("input >"); BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); String s = reader.readLine(); System.out.println("'" + s + "'"); } catch (IOException e) { e.printStackTrace(); } } }
print"input >"; chomp(my $s = <STDIN>); print"'$s'\n";
print "input >" s = STDIN.gets.chomp puts "'#{s}'"
最終更新日 : 2004.08.23
Number / 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
copyright 2000-2005
ARGIUS project