E
E
efim232014-12-02 22:43:02
go
efim23, 2014-12-02 22:43:02

How to implement initialization from the terminal in Go?

I'm looking for an alternative to cin from the C++ language for the Go language in order to initialize a variable from the terminal. Thank you.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
N
neolink, 2014-12-02
@efim23

reader := bufio.NewReader(os.Stdin)
fmt.Print("Enter text: ")
text, _ := reader.ReadString('\n')
fmt.Println(text)

S
SilentFl, 2014-12-03
@SilentFl

Do not fool a person's head, do not drag head-on solutions in Go. To pass command line parameters, there is a flag package, example one , example two .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question