在关于CFileDialog的程序中用这些代码时
CString TargetPath;
CString CurrentPath;
int Length=(dlg.GetPathName().GetLength()-dlg.GetFileName().GetLength()-1);
strncpy(CurrentPath.GetBuffer(0),dlg.GetPathName().GetBuffer(0),Length);
TargetPath.Format("%s\\%s" , CurrentPath , dlg.GetFileTitle());
出现错误,比方选择目录为D:\,文件名为111.htm时Length=2(正确),但是CurrentPath 却为“D:\1 0”,TargetPath为“D:\1 0\111”
改成下面的代码又正确
CString TargetPath;
CString CurrentPath;
int Length=(dlg.GetPathName().GetLength()-dlg.GetFileName().GetLength()-1);
CurrentPath.Format("%s",dlg.GetPathName().Left(Length));
TargetPath.Format("%s\\%s" , CurrentPath , dlg.GetFileTitle());
Length=2(正确),但是CurrentPath 却为“D:”,TargetPath为“D:\111”请问这是为什么……