Home

Fscanln

Fscanln is a function in the Go standard library, part of the fmt package. It reads formatted input from an input source and assigns the scanned values to the provided destinations. The scanning uses whitespace as separators and stops when a newline is encountered, with the newline being consumed but not assigned. The function signature is func Fscanln(r io.Reader, a ...interface{}) (n int, err error). It returns the number of successfully assigned values and an error value if one occurred.

Behavior and usage notes: Fscanln reads from a reader until a newline is found, filling the destination

Comparison with related functions: Fscanln differs from fmt.Fscan in that Fscan reads across lines without stopping

Example usage (conceptual): reading a line from standard input into a string and an integer, one line

variables
in
order.
If
the
end
of
the
input
is
reached
before
a
newline,
it
returns
io.EOF
(along
with
any
values
that
were
scanned).
If
a
token
cannot
be
assigned
to
a
destination,
an
error
is
returned.
Because
it
stops
at
a
newline,
Fscanln
is
well
suited
for
line-oriented
input
where
each
line
contains
a
fixed
number
of
fields.
at
a
newline,
while
Fscanln
strictly
terminates
after
processing
a
line.
This
makes
Fscanln
appropriate
when
your
input
is
organized
by
lines
and
you
want
to
enforce
one
line
per
scan
operation.
per
call,
and
handling
the
number
of
successfully
scanned
values
and
potential
errors.
Fscanln
is
a
practical
tool
for
simple,
line-based
parsing
in
Go
programs.