Last active
January 1, 2022 18:01
-
-
Save miguelmota/6310b4aae11b095a7f68d458ae5e9cf9 to your computer and use it in GitHub Desktop.
Golang stdin read line example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bufio" | |
"fmt" | |
"os" | |
) | |
func main() { | |
reader := bufio.NewReader(os.Stdin) | |
fmt.Print("Enter name: ") | |
text, err := reader.ReadString('\n') | |
if err != nil { | |
panic(err) | |
} | |
fmt.Printf("Your name is: %s\n", text) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment