如何将结构作为二进制数据写入golang中的文件?

What is the golang equivalent of the following C code ?

fwrite(&E, sizeof(struct emp), n, f);

I tried using

[]byte(i)

to convert it, but that won't work, it seems.

You should not do that, just use a serialization format that supports automatic serialization and deserialization. Go's standard library supports:

Gob: go binary encoding of structs. Recommended when you're not interested in interchange with other languages. https://golang.org/pkg/encoding/gob/

JSON: Welp, you know... If you need to exchange serialized data with other languages. https://golang.org/pkg/encoding/json/

XML: If you're feeling retro.

And of course protobuf is another option to consider, if you want type safe interchange with other languages, which json doesn't support. https://github.com/golang/protobuf