實現一個 Reader 類型,它發出 ASCII 字符“A”的無限流。我不明白這個問題,如何發出字符“A”?我應該將該字符設置為哪個變量?這是我嘗試過的: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函數
TA貢獻1836條經驗 獲得超4個贊
即使沒有拼寫錯誤,所謂的答案對我也不起作用。像我一樣嘗試,該字符串不會進入 b。
func (r MyReader) Read(b []byte) (int, error) {
return copy(b, "A"), nil
}
- 2 回答
- 0 關注
- 187 瀏覽
添加回答
舉報
0/150
提交
取消