问答详情
源自:5-3 Go语言-切片的更多操作方法

开头没有 package main import "fmt"

package main


import "fmt"

func main() {

    var numbers4 = [...]int{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}

    slice5 := numbers4[4:6:8]

    length := (2)

capacity := (4)

fmt.Printf("%v, %v\n", length == len(slice5), capacity == cap(slice5))

slice5 = slice5[:cap(slice5)]

slice5 = append(slice5, 11, 12, 13)

length = (7)

fmt.Printf("%v\n", length == len(slice5))

slice6 := []int{0, 0, 0}

copy(slice5, slice6)

e2 := (0)

e3 := (8)

e4 := (11)

fmt.Printf("%v, %v, %v\n", e2 == slice5[2], e3 == slice5[3], e4 == slice5[4])

}

/*卡了个把小时,开头没有

package main

import "fmt"

所以运行会出现如下信息,

package main: 

../mfs/usercode/golang/7416881/7514/index.go:1:1: expected 'package', found 'func*/


提问者:weixin_慕码人2442613 2019-01-03 15:42

个回答

  • 慕后端2477888
    2019-01-04 00:44:59

    卡了个把小时 扎心了 老铁....