2012-08-31 29 views
17

這裏未定義的是代碼:strconv.Itoa64(1234)給出了在golang

package main 
import (
    "strconv" 
    "fmt" 
) 
func main() { 
    t := strconv.Itoa64(1234) 
    fmt.Println(t) 
} 

以下是錯誤消息:

命令行-參數 \ test.go :7:未定義:strconv.Itoa64 [成品在0.2秒,退出代碼2]

謝謝!

回答

55

這是因爲Itoa64不是strconv包中函數的名稱。看起來你真的想要。

t := strconv.FormatInt(1234, 10) 

http://golang.org/pkg/strconv/#FormatInt

+0

太謝謝你了斯蒂芬,這是工作!有一些**令人迷惑的**信息,包括:http://stackoverflow.com/questions/8344210/strconv-itoatime-nanoseconds-error/8344775#8344775和http://golang.org/src/cmd /fix/strconv_test.go – Yster

+11

'strconv.Itoa64'在Go 1之前存在。這就是爲什麼存在衝突的信息。 –

+0

感謝您的信息。在進行編碼時,我經常在查找信息時遇到問題。在Go中編寫代碼時,您的主要信息來源是什麼? – Yster

0

你可以簡單地轉換這樣

func main() { 
    t := int64(1234) 
    fmt.Println(t) 
} 
+0

這不回答這個問題。 – digitaldreamer