运行一个读写文件的代码,出现断言ASSERT(m_hFile != INVALID_HANDLE_VALUE);
- C/C++ code
CFile d_file; if( !d_file.Open(_T("W.txt"), CFile::modeCreate | CFile::modeWrite) ) { CString str; for(dx=0;dx<m_num;dx++) { for(dy=0;dy<m_num;dy++) { str.Format("%lf ",*(m_D+dx*m_num+dy)); d_file.Write(str,str.GetLength()); } str.Format("\n\r"); d_file.Write(str,str.GetLength()); } d_file.Close(); }
某程序,加了以上代码后,出现断言ASSERT(m_hFile != INVALID_HANDLE_VALUE);感觉是d_file.Write(str,str.GetLength());除了问题。不知道怎么办,谢谢!
[解决办法]
ASSERT(m_hFile == INVALID_HANDLE_VALUE);这个是因为文件句柄无效导致的引起系统的断言的。
[解决办法]
- C/C++ code
if( d_file.Open(_T("W.txt"), CFile::modeCreate | CFile::modeWrite) )//应该是这样
[解决办法]
- C/C++ code
if (TRUE == d_file.Open(L"W.txt", CFile::modeCreate|CFile::modeWrite)){ ....;}