package mainimport "fmt"import "os"func Count(ch chan int, i int){ ch <- i file, err := os.OpenFile("data.dat",os.O_CREATE|os.O_APPEND,0777) if err !=nil{ fmt.Println("xxx") return } str := "abc" num,_ := file.WriteString(str) defer file.Close() fmt.Println(num)}func main(){ chs := make([]chan int, 10) for i:=0;i<10;i++ { chs[i] = make(chan int) go Count(chs[i], i) } for _, ch:= range(chs) { num:= <-ch fmt.Print(num) } fmt.Print("\n")}
Count方法中字符串怎么写不进去?
为什么Count方法中的打印就只打印一次?chs中明显写进了10次值.......
小白求大神解答................................
繁星点点滴滴
跃然一笑