Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

os: Add example showing how to read data from stdin #22421

kevinburke opened this Issue Oct 24, 2017 · 4 comments


None yet
6 participants
Copy link

kevinburke commented Oct 24, 2017

A pretty common task, especially for new programmers, is to ask the user to type in some value at the command line and then have the program act on it. (think "interactive maze game", "determine if word is palindrome", etc). It would be nice if we had an example in the os package showing how to do this.


This comment has been minimized.

Copy link

dpinela commented Oct 25, 2017

I don't think that belongs in the os package documentation (a new programmer is unlikely to look there first for help). What you suggest would belong more in a tutorial, like the Go tour, which already has a lot of basic examples, though nothing about reading console input.


This comment has been minimized.

Copy link
Contributor Author

kevinburke commented Oct 25, 2017

Ideally we'd add it in both places.


This comment has been minimized.

Copy link

rucuriousyet commented Oct 30, 2017

If this hasn't been taken yet, I should be able to do this. The line example (provided here: is perfect for what I think you are looking for. I may adapt the example but it should be a pretty quick addition to the docs...


This comment has been minimized.

Copy link

crvv commented Nov 2, 2017

I don't think a new programmer should use os or bufio to do this.
fmt is much simpler.

package main

import "fmt"

func main() {
    var x, y int
    fmt.Scan(&x, &y)
    fmt.Println(x + y)

@ianlancetaylor ianlancetaylor added this to the Unplanned milestone Mar 29, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.