fork(1) download
  1. package main
  2. import "fmt"
  3.  
  4. func main(){
  5. var i int
  6. var f float64
  7. var s string
  8. _, err := fmt.Scan(&i,&f,&s)
  9. if err == nil {
  10. fmt.Println("read 1 integer: ",i)
  11. fmt.Println("read 1 float64: ",f)
  12. fmt.Println("read 1 string: ",s)
  13. } else {
  14. fmt.Println("Error: ",err)
  15. }
  16. _, err = fmt.Scanln(&s)
  17. if err == nil {
  18. fmt.Println("read 1 line: ",s)
  19. } else {
  20. fmt.Println("Error: ",err)
  21. }
  22. }
Success #stdin #stdout 0s 420544KB
stdin
123
123.456
everybody loves ice cream


stdout
read 1 integer:  123
read 1 float64:  123.456
read 1 string:  everybody
Error:  Scan: expected newline