The go language reads the user's input

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

https://www.kancloud.cn/kancloud/the-way-to-go/72679



Examples

Func getmsg () (msg string) {  Reader: = Bufio. Newreader (OS. Stdin)   If err! = Nil {    FMT. Println (Err. Error ())  }  return}

Briefly summarize:

Reader is a pointer because of BUFIO. The interface of the Newreader () constructor is the func newreader (rd IO. Reader) *reader

(*reader, as can be seen from here)

1. Reader: = Bufio. Newreader (OS. Stdin), a reader was created

2.msg, err: = Reader. ReadString (' \ n ')
ReadString (Delim byte) is a method.

Reads to the Delim character and ends, and returns Error=nil to err.

So msg gets the OS. stdin the input string plus (' \ n ') wrapping. ( remember )

Finally, the MSG is returned, corresponding to the function name, and the msg+ (' \ n ') information is obtained.



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.