by xuxinhua1984:
The code:
package main
import (
"fmt"
)
func main() {
for i := 0; i < 2; i++ {
var name string
fmt.Print("Input Name:")
n, err := fmt.Scanf("%s", &name)
fmt.Println(n, err, name)
}
}
Build And Run.
Then, I input:golang,and enter,the result is:
Input Name:golang
1 <nil> golang
Input Name:0 unexpected newline
But on linux,the same code, the result is ok:
Input Name:golang
1 <nil> golang
Input Name:golang
1 <nil> golang
The reason is: on windows, The "enter" is "\r\n", but in fmt
package, it is only deal "\n".