当前位置: 代码迷 >> 综合 >> std::ifstream std::ofstream write read 读写文件必须加上ios::binary,否则会出错
  详细解决方案

std::ifstream std::ofstream write read 读写文件必须加上ios::binary,否则会出错

热度:21   发布时间:2024-01-05 00:08:24.0

std::ifstream is;

is.open(file2.c_str(), std::ofstream::in);

is.seekg(0, ios::end);

int len = is.tellg();

char * df = (char*)malloc(len + sizeof(char));
df[0] = '\0';
is.seekg(0, ios::beg);
is.read(df, len);
len = is.tellg();

is.close();

读取一aac文件,不加ios::binary, read后tellg,值为-1,加了ios::binary后值为文件的长度。

  相关解决方案