简体   繁体   中英

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

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 then 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();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM