Go's Scanln (GoLang)

So.. Today I tried to study about Go, programming language by Google, that i expect would be good replacement for C/C++/Java..

Instalation? easy~
sudo pacman -S go # ArchLinux
go version # go version go1.2.2 linux/amd64
running? easy~
go build try1.go && ./try1 # or
go run try1.go
input and output? easy~ ^^)b
package main
import (
func main(){
  var i int
  var f float64
  var s string
  r := bufio.NewReader(os.Stdin)
  _, err := fmt.Scan(&i,&f,&s)
  if err == nil {
   fmt.Println("read int, float and string:",i,f,s)
  } else {
  s, err = r.ReadString('\n')
  if err == nil {
   fmt.Println("read line:",s)
  } else {

 Just some tricy part, I expect that fmt.Scanln would behave like C++'s getline(cin,str) or Java's Scanner scan.nextLine(), but it doesn't.. oh well..

No comments :

Post a Comment

THINK: is it True? is it Helpful? is it Inspiring? is it Necessary? is it Kind?