第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

fmt.Scanf 在 Go 中無法正常工作

fmt.Scanf 在 Go 中無法正常工作

Go
動(dòng)漫人物 2021-08-23 17:18:07
我正在嘗試一個(gè)應(yīng)該測(cè)試 fmt.Scanf 的片段,但它似乎沒有按預(yù)期工作:package mainimport (    "fmt"    "time")func main() {    fmt.Println("What is your favorite color?")    var favoriteColor string    fmt.Scanf("%s", &favoriteColor)    fmt.Println("Fave color is", favoriteColor)    fmt.Println("What is your favorite food?")    var myfood string    fmt.Scanf("%s", &myfood)    fmt.Printf("I like %s too!\n", myfood)    fmt.Printf("Wait two seconds please...\n")    time.Sleep(2000 * time.Millisecond)    fmt.Printf("Your favorite color is %s, and the food you like best is %q\n", favoriteColor, myfood)}然而只接受第一個(gè)答案,程序繼續(xù)到最后然后返回:What is your favorite color?redFave color is redWhat is your favorite food?I like  too!Wait two seconds please...Your favorite color is red, and the food you like best is ""為什么第二個(gè) scanf 函數(shù)被忽略?這對(duì)我來說毫無意義。我在 Windows 7 上使用最新的 64 位軟件包安裝了 Go。
查看完整描述

1 回答

?
慕尼黑5688855

TA貢獻(xiàn)1848條經(jīng)驗(yàn) 獲得超2個(gè)贊

把 a 放在\n后面,%s這樣它就會(huì)消耗你輸入的換行符。否則換行進(jìn)入下一次掃描。


查看完整回答
反對(duì) 回復(fù) 2021-08-23
  • 1 回答
  • 0 關(guān)注
  • 236 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)