mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 01:55:35 +08:00
fix: coding style and file format for all example.
This commit is contained in:
@@ -1,38 +1,39 @@
|
||||
// read_csvfile.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
// "io/ioutil"
|
||||
// "strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
file, err := os.Open("products2.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var col1, col2, col3 []string
|
||||
for {
|
||||
var v1, v2, v3 string
|
||||
_, err := fmt.Fscanln(file, &v1, &v2, &v3)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
col1 = append(col1, v1)
|
||||
col2 = append(col2, v2)
|
||||
col3 = append(col3, v3)
|
||||
}
|
||||
|
||||
fmt.Println(col1)
|
||||
fmt.Println(col2)
|
||||
fmt.Println(col3)
|
||||
}
|
||||
/* Output:
|
||||
[ABC FUNC GO]
|
||||
[40 56 45]
|
||||
[150 280 356]
|
||||
*/
|
||||
// read_csvfile.go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
// "io/ioutil"
|
||||
// "strings"
|
||||
)
|
||||
|
||||
func main() {
|
||||
file, err := os.Open("products2.txt")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
var col1, col2, col3 []string
|
||||
for {
|
||||
var v1, v2, v3 string
|
||||
_, err := fmt.Fscanln(file, &v1, &v2, &v3)
|
||||
if err != nil {
|
||||
break
|
||||
}
|
||||
col1 = append(col1, v1)
|
||||
col2 = append(col2, v2)
|
||||
col3 = append(col3, v3)
|
||||
}
|
||||
|
||||
fmt.Println(col1)
|
||||
fmt.Println(col2)
|
||||
fmt.Println(col3)
|
||||
}
|
||||
|
||||
/* Output:
|
||||
[ABC FUNC GO]
|
||||
[40 56 45]
|
||||
[150 280 356]
|
||||
*/
|
||||
|
Reference in New Issue
Block a user