无论如何我可以将数据从fstream
(文件)传输到stringstream
(内存中的流)吗?
目前,我正在使用缓冲区,但这需要双倍内存,因为您需要将数据复制到缓冲区,然后将缓冲区复制到字符串流,直到您删除缓冲区,数据才会在内存中重复。
std::fstream fWrite(fName,std::ios::binary | std::ios::in | std::ios::out);
fWrite.seekg(0,std::ios::end); //Seek to the end
int fLen = fWrite.tellg(); //Get length of file
fWrite.seekg(0,std::ios::beg); //Seek back to beginning
char* fileBuffer = new char[fLen];
fWrite.read(fileBuffer,fLen);
Write(fileBuffer,fLen); //This writes the buffer to the stringstream
delete fileBuffer;`
有谁知道如何在不使用中间缓冲区的情况下将整个文件写入字符串流?