douya2982 2018-12-23 13:49
浏览 480
已采纳

单值上下文中的多值reader.ReadString()

This question already has an answer here:

Go newbie here.

I am trying to run very simple example on go1.11.4 windows/amd64

Here is my code below;
sandbox: https://play.golang.org/p/GoALi4HYx3L

package main

import (
    "bufio"
    "fmt"
    "os"
)

func main() {
    fmt.Print("Enter a grade: ")
    reader := bufio.NewReader(os.Stdin)
    fmt.Print("Enter text: ")
    input := reader.ReadString('
')
    fmt.Println(input)
}

And I am getting following error:

prog.go:13:28: multiple-value reader.ReadString() in single-value context

Am I missing something here?

</div>
  • 写回答

1条回答 默认 最新

  • duanqian1888 2018-12-23 13:54
    关注

    Check the documentation for ReadString, especially the part that describes return values (Tip: it is in the title of the section).

    https://golang.org/pkg/bufio/#Reader.ReadString

    Also, it worse check this reading also https://gobyexample.com/multiple-return-values

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?