我希望在使用 sscanf 處理字符串時忽略特定字段。sscanf 的手冊頁說An optional '*' assignment-suppression character: scanf() reads input as directed by the conversion specification, but discards the input. No corresponding pointer argument is required, and this specification is not included in the count of successful assignments returned by scanf().嘗試在 Golang 中使用它,忽略第三個字段:if c, err := fmt.Sscanf(str, " %s %d %*d %d ", &iface.Name, &iface.BTx, &iface.BytesRx); err != nil || c != 3 {編譯正常,但在運行時 err 設置為:bad verb %* for integerGolang doco 沒有特別提到 %* 轉換規范,但它確實說,Package fmt implements formatted I/O with functions analogous to C's printf and scanf.這并不表示 %* 沒有實現,所以......我做錯了嗎?或者它只是被悄悄地省略了?...但是,它為什么要編譯?
- 1 回答
- 0 關注
- 415 瀏覽
添加回答
舉報
0/150
提交
取消