From the course: Learning the Go Standard Library
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Reading from standard input - Go Tutorial
From the course: Learning the Go Standard Library
Reading from standard input
- All right, so So the last example we're going to look at in this chapter is reading from standard input. Which, you know, is a pretty important feature if you're building a console application that needs to get input from the user. So there are a few different ways of doing this. So I'm going to demonstrate the shortest and the easiest way. So here in my code, I'm going to open up standard in and I'm just going to start. And what I'm going to do is, I'm going to need the bufio package, which gives buffered IO operations. So let's go ahead and import that. And we'll also need the OS package which gives us the standard in variable for the standard input stream. And we'll cover these packages a little bit later in the course. So let's start by creating our reader which we'll use the new reader function of the bufio package. So I'm going to create a reader and that's going to be the result of bufio.NewReader. And…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.