bigblind
bigblind

Reputation: 12867

go fmt.Scan into Array

The fmt package has a Scan function that reads stdin, and writes consecutive space separated values to the variables you provide. Is there a way to use this with Slices, so that I could create a slice of sice n, and have scan read n values and put them into the slice?

Upvotes: 3

Views: 1677

Answers (1)

Volker
Volker

Reputation: 42422

Just wrap your call to fmt.Scan in a for loop.

Upvotes: 2

Related Questions