Home

Scanln

Scanln is a function in the Go programming language’s standard library, within the fmt package. It reads input from standard input and assigns the scanned values to the provided variables. The function signature is func Scanln(a ...*T) (n int, err error), where a is a list of pointers to the destinations for the scanned values. It treats whitespace as a separator and reads input up to and including a newline, stopping after the newline has been read. The number of successfully scanned items is returned as n, along with any error encountered as err.

In practice, Scanln is used to obtain simple, line-oriented input from the user. Values are scanned in

If the input line contains tokens that do not match the expected types, an error is returned

Scanln is one of several related functions in the fmt package for input: it shares behavior patterns

the
order
of
the
supplied
destinations
and
must
be
compatible
with
the
respective
types
(for
example,
a
string
destination
will
store
a
word
or
token,
an
int
destination
will
parse
a
number,
etc.).
The
function
waits
for
the
user
to
press
Enter
to
complete
the
line,
making
it
straightforward
for
interactive
prompts
but
less
suited
to
complex
input
parsing.
and
scanning
stops.
If
the
input
ends
before
a
newline
is
read,
an
error
such
as
io.EOF
may
be
returned.
Any
input
beyond
what
the
destinations
can
hold
may
remain
unread
in
the
input
buffer.
with
Scan
and
Scanf,
and
there
are
reader-based
variants
such
as
Fscan
and
Fscanln
for
scanning
from
an
io.Reader
instead
of
standard
input.