很奇怪的错误,明明文件存在,而且debug显示路径正确却总是打开失败
TCHAR exeFullPath[MAX_PATH];
CString strPath;
//得到运行的exe路径
GetModuleFileName(NULL,exeFullPath,MAX_PATH);
strPath=(CString)exeFullPath;
int position=strPath.ReverseFind('\\');
strPath=strPath.Left(position);
position = strPath.ReverseFind('\\');
strPath = strPath.Left(position+1);
//以上是取得了工程的路径
std::string fName = strPath;
//工程路径加上相对路径
strTrainFile = fName.append(strTrainFile);
std::ifstream inFile(strTrainFile.c_str());
if( inFile.fail() )
{
return false;
}
在工程中有个文件,在trainData\matrixFeature.txt中.
我现在首先取得工程的路径(strPath),然后添加相对路径(trainData\matrixFeature.txt),经过查看,strTrainFile确实是正确的路径,但是就是每次打开都失败,高手看看为什么吧,谢谢.