I'm trying to learn Go, but stuck with this one: http://ideone.com/hbCamr or http://ideone.com/OvRw7t
package main
import "fmt"
func main(){
var i int
var f float64
var s string
_, err := fmt.Scan(&i)
if err == nil {
fmt.Println("read 1 integer: ",i)
} else {
fmt.Println("Error: ",err)
}
_, err = fmt.Scan(&f)
if err == nil {
fmt.Println("read 1 float64: ",f)
} else {
fmt.Println("Error: ",err)
}
_, err = fmt.Scan(&s)
if err == nil {
fmt.Println("read 1 string: ",s)
} else {
fmt.Println("Error: ",err)
}
_, err = fmt.Scanln(&s)
if err == nil {
fmt.Println("read 1 line: ",s)
} else {
fmt.Println("Error: ",err)
}
}
for this input:
123
123.456
everybody loves ice cream
the output was:
read 1 integer: 123
read 1 float64: 123.456
read 1 string: everybody
Error: Scan: expected newline
is this the expected behavior? why doesn't it work like C++ getline? http://ideone.com/Wx8z5o