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

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后值为文件的长度。

你可能感兴趣的:(std::ifstream std::ofstream write read 读写文件必须加上ios::binary,否则会出错)