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)
  9. if err == nil {
  10. fmt.Println("read 1 integer: ",i)
  11. } else {
  12. fmt.Println("Error: ",err)
  13. }
  14. _, err = fmt.Scan(f)
  15. if err == nil {
  16. fmt.Println("read 1 float64: ",f)
  17. } else {
  18. fmt.Println("Error: ",err)
  19. }
  20. _, err = fmt.Scan(s)
  21. if err == nil {
  22. fmt.Println("read 1 string: ",s)
  23. } else {
  24. fmt.Println("Error: ",err)
  25. }
  26. _, err = fmt.Scanln(&s)
  27. if err == nil {
  28. fmt.Println("read 1 line: ",s)
  29. } else {
  30. fmt.Println("Error: ",err)
  31. }
  32. }
Success #stdin #stdout 0s 420608KB
stdin
123
123.456
everybody loves ice cream


stdout
Error:  Scan: type not a pointer: int
Error:  Scan: type not a pointer: float64
Error:  Scan: type not a pointer: string
read 1 line:  123