C read binary stdin

前端 未结 8 2197
难免孤独
难免孤独 2020-11-30 04:51

I\'m trying to build an instruction pipeline simulator and I\'m having a lot of trouble getting started. What I need to do is read binary from stdin, and then store it in me

8条回答
  •  失恋的感觉
    2020-11-30 05:25

    I don't know what OS you are running, but you typically cannot "open stdin in binary". You can try things like

    int fd = fdreopen (fileno (stdin), outfname, O_RDONLY | OPEN_O_BINARY);
    

    to try to force it. Then use

    uint32_t opcode;
    read(fd, &opcode, sizeof (opcode));
    

    But I have no actually tried it myself. :)

提交回复
热议问题