我希望在使用 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 回答
- 1 回答
- 0 关注
- 382 浏览
添加回答
举报
0/150
提交
取消