相对路径,该怎么解决
相对路径
我编写的一个读图片的程序,使用GetModuleFileName读取相对路径,编译时提示error C2664: 'ReverseFind' : cannot convert parameter 1 from 'char [58]' to 'char'这个错误,请问怎么解决?
程序如下:
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer();
int nPos; nPos=sPath.ReverseFind("..\\ElecDosimetryDB\\Debug\\6maleRat\\maleRat_800MHz_Top6.jpg");
sPath=sPath.Left(nPos);
------解决方案--------------------
ReverseFind的参数是一个字符,你给他的 是字符串肯定报错啊
------解决方案--------------------
ReverseFind是要找某个字符的位置。
你把字符串输入当然找不到了。
应该用'\\'之类的。如果要长度的话直接GetLength也可以的
------解决方案--------------------
我编写的一个读图片的程序,使用GetModuleFileName读取相对路径,编译时提示error C2664: 'ReverseFind' : cannot convert parameter 1 from 'char [58]' to 'char'这个错误,请问怎么解决?
程序如下:
CString sPath;
GetModuleFileName(NULL,sPath.GetBufferSetLength(MAX_PATH+1),MAX_PATH);
sPath.ReleaseBuffer();
int nPos; nPos=sPath.ReverseFind("..\\ElecDosimetryDB\\Debug\\6maleRat\\maleRat_800MHz_Top6.jpg");
sPath=sPath.Left(nPos);
------解决方案--------------------
ReverseFind的参数是一个字符,你给他的 是字符串肯定报错啊
------解决方案--------------------
ReverseFind是要找某个字符的位置。
你把字符串输入当然找不到了。
应该用'\\'之类的。如果要长度的话直接GetLength也可以的
------解决方案--------------------
HMODULE module = GetModuleHandle(0);
GetModuleFileName(module, pFileName, MAX_PATH);
CString csFullPath(pFileName);
if(type == Path_ExeFolder) //应用程序所在路径/debug路径,不包括文件名
{
int nPos = csFullPath.ReverseFind( _T('\\') );
if( nPos < 0 )
return CString("");
else
return csFullPath.Left( nPos );
}