获取整数输入
()
| 505 | |
| 506 | // 获取整数输入 |
| 507 | func getIntInput() int { |
| 508 | reader := bufio.NewReader(os.Stdin) |
| 509 | for { |
| 510 | input, _ := reader.ReadString('\n') |
| 511 | input = strings.TrimSpace(input) |
| 512 | if num, err := strconv.Atoi(input); err == nil { |
| 513 | return num |
| 514 | } |
| 515 | fmt.Print("请输入有效的数字: ") |
| 516 | } |
| 517 | } |
| 518 | |
| 519 | // 获取字符串输入 |
| 520 | func getStringInput() string { |
nothing calls this directly
no outgoing calls
no test coverage detected