How to Use os.Stdin, os.Stdout, and os.Stderr

Use os.Stdin for input, os.Stdout for output, and os.Stderr for errors in Go programs.

Use os.Stdin to read user input, os.Stdout for normal output, and os.Stderr for error messages.

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	fmt.Print("Enter text: ")
	if scanner.Scan() {
		fmt.Fprintln(os.Stdout, "You entered:", scanner.Text())
	} else if err := scanner.Err(); err != nil {
		fmt.Fprintln(os.Stderr, "Error reading input:", err)
	}
}