Home Software Engineering Learn from Commonplace Enter in Golang

Learn from Commonplace Enter in Golang

0
Learn from Commonplace Enter in Golang

[ad_1]

Studying from “customary enter” is de facto helpful if you’re making a command-line software and require consumer enter.

bundle important

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

func important() {
    reader := bufio.NewReader(os.Stdin)
    s, _ := reader.ReadString('n')
    fmt.Printf(s)
}

First setup a brand new bufio reader, then use ReadString perform, with a default wait character, which now we have set to a newline (n).

The applying will pause at this level and look ahead to consumer enter earlier than continuing.

[ad_2]

LEAVE A REPLY

Please enter your comment!
Please enter your name here