我试图通过fmt.scanf输入一个句子存入变量,但是scanf函数将空格后面的单词识别成了下一次输入的内容。请问如何避免这个问题呢?代码如下所示:package mainimport ( "fmt" "strings")func main() { var quote string var name string fmt.Print("What is the quote? ") fmt.Scanf("%s", "e) fmt.Print("Who said it? ") fmt.Scanf("%s", &name) fmt.Printf("%s says, \"%s\"", strings.Title(name), quote)}输出如下:What is the quote? I am Groot
Who said it? Am says, "I"已尝试过bufio包,但是我想找到只用fmt包的方法
2 回答
- 2 回答
- 0 关注
- 1519 浏览
添加回答
举报
0/150
提交
取消