package main import ( "bufio" "fmt" "os" ) func main() { reader := bufio.NewReader(os.Stdin) fmt.Print("Enter a string: ") str, err := reader.ReadString('\n') if err != nil { fmt.Println("Error reading input:", err) return } // read and print each rune from the input string for _, r := range str { fmt.Printf("%c\n", r) } }
package main import ( "bufio" "fmt" "strings" ) func main() { input := "こんにちは\n" reader := bufio.NewReader(strings.NewReader(input)) // read and print each rune from the input string for { r, _, err := reader.ReadRune() if err != nil { break } fmt.Printf("%c\n", r) } }In this example, we create a bufio.Reader object to read input from a string. We set the input string to "こんにちは\n", which means "hello" in Japanese. We then loop over the input string using the ReadRune method to print each rune. Both examples use the bufio package in Go. The package provides buffered I/O operations that allow efficient reading and writing of data streams. The Reader type in the package provides methods to read data from an io.Reader object and return it in different formats. The ReadRune method reads and returns the next Unicode character (rune) from the input stream.