實(shí)現(xiàn)一個(gè) Reader 類型,它發(fā)出 ASCII 字符“A”的無限流。我不明白這個(gè)問題,如何發(fā)出字符“A”?我應(yīng)該將該字符設(shè)置為哪個(gè)變量?這是我嘗試過的:package mainimport "code.google.com/p/go-tour/reader"type MyReader struct{}// TODO: Add a Read([]byte) (int, error) method to MyReader.func (m MyReader) Read(b []byte) (i int, e error) { b = append(b,'A') // this is wrong.. return 1, nil // this is also wrong..}func main() { reader.Validate(MyReader{}) // what did this function expect?}
2 回答

HUH函數(shù)
TA貢獻(xiàn)1836條經(jīng)驗(yàn) 獲得超4個(gè)贊
即使沒有拼寫錯(cuò)誤,所謂的答案對(duì)我也不起作用。像我一樣嘗試,該字符串不會(huì)進(jìn)入 b。
func (r MyReader) Read(b []byte) (int, error) {
return copy(b, "A"), nil
}
- 2 回答
- 0 關(guān)注
- 179 瀏覽
添加回答
舉報(bào)
0/150
提交
取消