亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

寫入文件 int 轉換為字符串

寫入文件 int 轉換為字符串

Go
胡說叔叔 2022-01-17 10:44:20
我只想簡單地寫入文件從 int 轉換的字符串。但是 f.WriteString 而不是 number 從 ASCII 碼表中寫入符號。我預計“noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899”但是卻得到了“noReport = ? nr3h = i nr2h = ¢ nr1h = & ok = ?”
查看完整描述

2 回答

?
慕萊塢森

TA貢獻1810條經驗 獲得超4個贊

要使用您的整數獲取字符串,我建議使用 fmt.Sprintf

會是這樣的;

s := fmt.Sprintf("noReport = %d nr3h = %d nr2h = %d nr1h = %d ok = 16899", 12320, 162, 38)

這會將值分配"noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899"s.


查看完整回答
反對 回復 2022-01-17
?
慕無忌1623718

TA貢獻1744條經驗 獲得超4個贊

https://play.golang.org/p/QAXJ4aJBy3


fmt.Printf("os.StdOut is %T\n", os.Stdout)

os.Stdout.WriteString("noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899 \n")

os.Stdout.WriteString("12320")


//Output

//os.StdOut is *os.File

//noReport = 12320 nr3h = 105 nr2h = 162 nr1h = 38 ok = 16899 

//12320

對我來說很好。


請給我們您的代碼。


UDP


string(noReport), noReport 是整數嗎?那是預期的行為。


使用strconv.Itoa(無報告)。


noReport := 12320

nr3h := 105

nr2h := 162

nr1h := 38

ok := 16899

os.Stdout.WriteString("noReport = "+ strconv.Itoa(noReport) + " nr3h = " + strconv.Itoa(nr3h)+ " nr2h = "+ strconv.Itoa(nr2h)+ " nr1h = "+ strconv.Itoa(nr1h) + " ok = "+ strconv.Itoa(ok)+ "\n") 

或 evanmcdonnal 的回答。


查看完整回答
反對 回復 2022-01-17
  • 2 回答
  • 0 關注
  • 153 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號