douqianzha6213
2019-06-08 20:44
浏览 55
已采纳

Golang程序在Windows 10中给出了不正确的结果

First of all, I am a newbie to Go programming. I have a simple Golang program which is giving the correct output in Linux environment but not in my Windows 10 PC.

The code is as follows:

package main

import (
    "bufio"
    "fmt"
    "os"
    "strconv"
    "strings"
)

func main() {
    reader := bufio.NewReader(os.Stdin)
    fmt.Print("Enter text: ")
    text, _ := reader.ReadString('
')
    tarr := strings.Split(strings.Trim(text, "
"), " ")

    for i := 0; i < len(tarr); i++ {
        num, _ := strconv.ParseInt(tarr[i], 10, 32)
        fmt.Println(num)
    }

    fmt.Println(tarr)
    reader.ReadString('
')
}

If I enter 1 2 3 as input from the terminal, I am getting the following output in Windows 10 (go version go1.12.5 windows/amd64):

1
2
0
]1 2 3

I am getting the following output in Linux Elementary OS (go version go1.12.5 linux/amd64)

1
2
3
[1 2 3]

Can anyone explain why this is happening?

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

相关推荐 更多相似问题