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

Open
kevinburke opened this issue Oct 24, 2017 · 4 comments
Open

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

kevinburke opened this issue Oct 24, 2017 · 4 comments

Comments

@kevinburke
Copy link
Contributor

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.

@dpinela
Copy link
Contributor

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.

@kevinburke
Copy link
Contributor Author

Ideally we'd add it in both places.

@ghost
Copy link

ghost commented Oct 30, 2017

If this hasn't been taken yet, I should be able to do this. The line example (provided here: https://golang.org/pkg/bufio/#Scanner) 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...

@crvv
Copy link
Contributor

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
Projects
None yet
Development

No branches or pull requests

5 participants