#include <afx.h>
#include <iostream>
using namespace std;void Recurse(LPCTSTR pstr)
{
CFileFind finder; // build a string with wildcards
CString strWildcard(pstr);
strWildcard += _T("//*.*"); // start working for files
BOOL bWorking = finder.FindFile(strWildcard); while (bWorking)
{
bWorking = finder.FindNextFile(); // skip . and .. files; otherwise, we'd
// recur infinitely! if (finder.IsDots())
continue; // if it's a directory, recursively search it if (finder.IsDirectory())
{
CString str = finder.GetFilePath();
cout << (LPCTSTR) str << endl;
Recurse(str);
}
} finder.Close();
} void _tmain()
{
if (!AfxWinInit(::GetModuleHandle(NULL), NULL,::GetCommandLine(), 0))
cout << "panic!" << endl;
else
Recurse(_T("C:"));
} 请问一下,为什么会出现error C2065: 'AfxWinInit' : undeclared identifier这种错误?
// this file must be compiled with the /GX and /MT options:
// cl /GX /MT thisfile.cpp#include <afx.h>
#include <afxdb.h>
#include <iostream.h>int main()
{
// try to initialize MFC if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
cerr << "MFC failed to initialize!" << endl;
return 1;
} // try to connect to an ODBC database that doesn't exist
// (this wouldn't work at all without initializing MFC) CDatabase db;
try
{
db.Open("This Databsae Doesn't Exist"); // we shouldn't realistically get here cout << "Successful!" << endl;
cout << "Closing ... ";
db.Close();
cout << "Closed!" << endl;
}
catch (CDBException* pEx)
{
// we got an exception! print an error message
// (this wouldn't work without initializing MFC) char sz[1024]; cout << "Error: ";
if (pEx->GetErrorMessage(sz, 1024))
cout << sz;
else
cout << "No error message was available";
cout << endl; pEx->Delete();
return 1;
} return 0;
}
2、如MSDN所注明:// this file must be compiled with the /GX and /MT options:
参考下图修改项目设置中runtime library为multithread