开发者

Is there a way to send a CString to a CFile without writing an actual file?

开发者 https://www.devze.com 2023-01-09 16:18 出处:网络
I have data stored in a CString and it needs to be parsed by an XML parser library. The problem is the XML parser takes in a CFile. It\'s not ideal to write out the CString to a text file and the开发者

I have data stored in a CString and it needs to be parsed by an XML parser library. The problem is the XML parser takes in a CFile. It's not ideal to write out the CString to a text file and the开发者_JAVA百科n reload it into a CFile. Is there any way to directly send the CString to the CFile without making an intermediate output file?


You should be able to use CMemFile to accomplish this. It inherits from CFile and allows you to specify an arbitrary buffer for data. The following sample code should work:

CString strData;
CMemFile memFile( (BYTE*)strData.GetBuffer() , (strData.GetLength() + 1) * sizeof(TCHAR) );

//Do something with memFile

strData.ReleaseBuffer();
0

精彩评论

暂无评论...
验证码 换一张
取 消