import ( "bufio" "fmt" "os" ) func main() { file, err := os.Open("file.txt") if err != nil { panic(err) } defer file.Close() scanner := bufio.NewScanner(file) for scanner.Scan() { fmt.Println(scanner.Text()) } if err := scanner.Err(); err != nil { panic(err) } }
import ( "bufio" "fmt" "os" ) func main() { scanner := bufio.NewScanner(os.Stdin) fmt.Print("Enter your name: ") scanner.Scan() name := scanner.Text() fmt.Printf("Hello, %s!\n", name) }In this example, `bufio.NewScanner(os.Stdin)` is used to create a new Scanner object to read input from the keyboard. The `Scan()` method reads the user's input, which is then stored in the `name` variable. The `fmt.Printf()` function is used to print a personalized message to the console.