实现原理:输入int型
func getString() string {
s, _ := reader.ReadString('\r')
s = strings.Replace(s, "\r", "", -1)
s = strings.Replace(s, "\n", "", -1)
return s
}
func getInt() int {
s := getString()
i, _ := strconv.Atoi(s)
return i
}
先把s当string读入,再把string替换,最后返回i.
引用包:
import(
"os"
"strconv"
"strings"
)