Question: How do I add a prompt to the beginning of a Scan statement in GoLang?
Enter Phrase:
Hello World!
You typed: Hello world!
Enter Phrase: Hello world!
You typed: Hello world!
package main
import(
"fmt"
)
func main() {
var phrase string
fmt.Println("Enter Phrase: ")
fmt.Scan(&phrase)
fmt.Println("You typed: ", phrase)
}
PS I'm sorry for posting such an elementary question. I have spent several hours researching, and I genuinely cannot find the answer.
I figured it out.
Here is one solution in case other people have this problem:
use fmt.Print before your scan statement.
package main
import(
"fmt"
)
func main() {
var phrase string
fmt.Print("Enter Phrase: ")
fmt.Scanln(&phrase)
fmt.Println("You typed: ", phrase)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.