作者:爱吃肉肉的狼 | 来源:互联网 | 2023-10-10 21:29
如何在 Golang 获取用户输入?
原文:https://www . geesforgeks . org/如何从 golang 用户那里获取输入/
Scanln 功能可用于在 Golang 中接受用户的输入。下面是从用户处获取输入的示例:
// Golang program to show how
// to take input from the user
package main
import "fmt"
// main function
func main() {
// Println function is used to
// display output in the next line
fmt.Println("Enter Your First Name: ")
// var then variable name then variable type
var first string
// Taking input from user
fmt.Scanln(&first)
fmt.Println("Enter Second Last Name: ")
var second string
fmt.Scanln(&second)
// Print function is used to
// display output in the same line
fmt.Print("Your Full Name is: ")
// Addition of two string
fmt.Print(first + " " + second)
}
现在保存该文件并执行,如下图所示:
关于节目的描述: