我想我的代碼的std :: fstream的轉換到std :: filebuf:fstream的緩衝作品,filebuf緩衝不
fstream的版本(原文):
std::ifstream stream(file);
stream.seekg(0,std::ios::end);
size_t fileSize = stream.tellg();
char * dataBuf = new char[fileSize];
stream.seekg(0);
stream.read(dataBuf, fileSize);
LoadData(dataBuf);
filebuf版本(轉換):
std::filebuf * stream = new std::filebuf;
stream->open(file, std::ios::in);
size_t fileSize = stream->pubseekoff(0, std::ios::end);
char * dataBuf = new char[fileSize];
stream->pubseekpos(0);
stream->pubsetbuf(dataBuf, fileSize);
LoadData(dataBuf);
的filebuf
版本似乎沒有得到加載。我不知道我錯過了什麼,因爲fileSize
s是相同的,並且dataBuf
s返回相同的字符串。我應該執行其他功能嗎?