Sonntag, 29. November 2009

input from stdion in go


package main

import (
"os"; "fmt"; "bufio";
)

func main() {

fmt.Print("input your name: ");

br := bufio.NewReader(os.Stdin);

name, _ := br.ReadString('\n');

fmt.Println();
fmt.Println("your name is: ", name);

}



func NewReader(rd io.Reader) *Reader NewReader returns a new Reader whose buffer has the default size.

func (b *Reader) ReadString(delim byte) (line string, err os.Error) read until delim byte.
here we read until enter.

Keine Kommentare:

Kommentar veröffentlichen