fmt.Printf的輸出為什么是覆蓋滾動(dòng)顯示的而不是逐句輸出全部顯示?
//?run?performs?a?proof-of-work func?(pow?*ProofOfWork)?Run()?(int,?[]byte)?{ ???var?hashInt?big.Int ???var?hash?[32]byte ???nonce?:=?0 ???fmt.Printf("mining?the?block?containing?\"%s\"\n",?pow.block.Data) ???for?nonce?<?maxNonce?{ ??????data?:=?pow.prepareData(nonce) ??????hash?=?sha256.Sum256(data) ??????fmt.Printf("\r%x",?hash) ??????hashInt.SetBytes(hash[:]) ??????if?hashInt.Cmp(pow.target)?==?-1?{ ?????????break ??????}?else?{ ?????????nonce++ ??????} ???} ???fmt.Print("\n\n") ???return?nonce,?hash[:] }
這里的run方法,for循環(huán)里面的fmt.Printf的輸出為什么是覆蓋滾動(dòng)顯示的而不是逐句輸出全部顯示?
2020-02-03
\r 代表回車,每行打印完后,下一次光標(biāo)會(huì)移至改行的行首,重新覆蓋打印;\n 是換行,這里換成\n就是全部顯示