unicode文本 转换为CString对象

 

封装函数:

BOOL txtFileToCString(CString filePath,CString &fileContent)
{
	CStdioFile readFile;
	if (!readFile.Open(filePath,CFile::modeReadWrite|CFile::typeBinary))
		return FALSE;

	ULONGLONG  len=readFile.GetLength();
	byte *pByte=new byte[len];
	memset(pByte,0,sizeof(byte)*len);

	if (len>0)
	{
		WORD sign;
		readFile.SeekToBegin();
		readFile.Read(&sign,2);
		if (sign!=0xfeff)
		{
			AfxMessageBox(L"录入文件不是Unicode");
			return FALSE;
		}else{
			readFile.Read(pByte,len-2);
			fileContent=(WCHAR*)pByte;
			delete [] pByte;
			return TRUE;
		}
	}
	
	return FALSE;
}


 

你可能感兴趣的:(byte)