outfile << pContent;//不可以用这个,因为不能写完全,比如遇到字符串中出现/0就终止了
bool CTestEn_DecryptDLLDlg::WriteDataFile(CString strFileName, char *pContent, int nLen)
{
ofstream outfile(strFileName, ios::out | ios::binary | ios::ate | ios::app);
if (!outfile)
{
AfxMessageBox(_T("Unable to open outfile"));
return false;
}
//for (int i = 0; i < nLen; ++i)
//{
// outfile << pContent[i];
//}
//outfile << pContent;//不可以用这个,因为不能写完全,比如遇到字符串中出现/0就终止了
outfile.write(pContent, nLen);
outfile.close();
}
bool CTestEn_DecryptDLLDlg::ReadDataFile(CString strFileName, char *pContent, int &nLen)
{
ifstream inFile(strFileName, ios::in | ios::binary);
if (!inFile)
{
AfxMessageBox(_T("Unable to open inFile"));
return false;
}
inFile.seekg(0, ios::beg);
//int i = 0;
//while (!inFile.eof())
//{
// inFile.get(pContent[i]);
// ++i;
//}
//nLen = i - 1;
memset(pContent, 0, nLen);//初始化FileContent
inFile.read(pContent, nLen);//读取数据
inFile.close();//关闭ifstream对像
return true;
}