package main import ( "bufio" "fmt" "os" ) func main() { reader := bufio.NewReader(os.Stdin) fmt.Print("Enter text: ") slice, err := reader.ReadSlice('\n') if err != nil { fmt.Println(err) return } fmt.Printf("The slice is: %v", slice) }
package main import ( "bufio" "fmt" "strings" ) func main() { reader := bufio.NewReader(strings.NewReader("hello\nworld\n")) for { line, err := reader.ReadSlice('\n') if err != nil { break } fmt.Printf("The slice is: %v", line) } }This example uses a string reader to simulate reading lines from a file. ReadSlice is called repeatedly until the end of the string is reached. Each slice is printed to the console. The package library for ReadSlice is bufio.