golang accepting input with spaces

av192 picture av192 · Dec 11, 2014 · Viewed 13.3k times · Source

I'm just starting with GO and I understand that SCANF uses spaces as a separator in GO.

fmt.Scanf("%s",&input)

I cant really find a way to accepts inputs that contain spaces as valid characters.

Answer

rchlin picture rchlin · Jun 12, 2015

you can use bufio.Reader and os.Stdin:

import(
  "bufio"
  "os"
)

in := bufio.NewReader(os.Stdin)

line, err := in.ReadString('\n')