1,windows cmd 结束输入问题

func main() {
    counts := make(map[string]int)
    countLines(os.Stdin, counts)
    fmt.Println(counts)
}

func countLines(f *os.File, counts map[string]int) {
    input := bufio.NewScanner(f)
    for input.Scan() {
        if "gp" == input.Text() {
            break
        }
        counts[input.Text()]++
    }
}

linux 下直接用ctrl+D能结束当前输入,但是在windows下没找到合适的方法,现在是用的在代码中显式的判断

if “gp" == input.Text(),用ctrl+C会导致后面的代码很可能不能顺利执行

 

Golang遇到的问题记录

 

相关文章:

  • 2021-07-25
  • 2022-12-23
  • 2021-11-21
  • 2021-11-08
  • 2021-04-01
  • 2021-05-20
  • 2021-08-27
  • 2021-06-14
猜你喜欢
  • 2021-09-19
  • 2021-06-21
  • 2022-12-23
  • 2021-09-29
  • 2021-07-08
  • 2021-09-03
  • 2021-05-21
相关资源
相似解决方案