Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
26
Task/Input-loop/Go/input-loop-1.go
Normal file
26
Task/Input-loop/Go/input-loop-1.go
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"io"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
in := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
s, err := in.ReadString('\n')
|
||||
if err != nil {
|
||||
// io.EOF is expected, anything else
|
||||
// should be handled/reported
|
||||
if err != io.EOF {
|
||||
log.Fatal(err)
|
||||
}
|
||||
break
|
||||
}
|
||||
// Do something with the line of text
|
||||
// in string variable s.
|
||||
_ = s
|
||||
}
|
||||
}
|
||||
24
Task/Input-loop/Go/input-loop-2.go
Normal file
24
Task/Input-loop/Go/input-loop-2.go
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"log"
|
||||
"os"
|
||||
)
|
||||
|
||||
func main() {
|
||||
s := bufio.NewScanner(os.Stdin)
|
||||
// Select the split function, other ones are available
|
||||
// in bufio or you can provide your own.
|
||||
s.Split(bufio.ScanWords)
|
||||
for s.Scan() {
|
||||
// Get and use the next 'token'
|
||||
asBytes := s.Bytes() // Bytes does no alloaction
|
||||
asString := s.Text() // Text returns a newly allocated string
|
||||
_, _ = asBytes, asString
|
||||
}
|
||||
if err := s.Err(); err != nil {
|
||||
// Handle/report any error (EOF will not be reported)
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue