read equivalent for filebuf?

前端 未结 4 761
萌比男神i
萌比男神i 2021-01-27 05:39
typedef struct {
  char c[20];
  int i;
} header;

void foo(std::string s) {
  std::ifstream ifs(s.c_str(), std::ios_base::binary | std::ios_base::in);
  if (ifs) {
             


        
4条回答
  •  心在旅途
    2021-01-27 06:05

    there is a read for ifstream

    Yes, and that's what you use to read unformatted data from the stream; hence the name.

    if I'm supposed to use that method, what is the point of filebuf ?

    It's used by the stream to handle low-level file access and buffering. You can access it if you need to mess around with those details, but usually there's no need to. You certainly wouldn't mess around with it if you just want to read from the stream.

提交回复
热议问题