package main
import (
"bufio"
"fmt"
"os"
)
func main() {
reader := bufio.NewReader(os.Stdin)
input, _ := reader.ReadBytes('\n') // hello world
fmt.Printf("input: %v\n", input) // input: [104 101 108 108 111 32 119 111 114 108 100 13 10]
u := []byte("hello world\n")
fmt.Printf("u: %v\n", u) // u: [104 101 108 108 111 32 119 111 114 108 100 10]
}
代码如上,输入和打印见注释。为何两组[]byte的后面俩byte不同啊
因为Windows下的回车是\r\n,而linux下的回车是\n,13对应 \r 10对应\n