Saturday, September 30, 2023
HomeSoftware EngineeringLearn from Commonplace Enter in Golang

Learn from Commonplace Enter in Golang


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.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments