如何转换真实路径 CString c++



>我有一个真正的窗口路径:

CString path = "C:Programs File (x86)Program folderexec.exe";

如何将其转换为

CString path = "C:\Programs File (x86)\Program folder\exec.exe";

我用path.Replace(L"\", L"\\");试过了,但失败了。

在您的一条评论中,您写道您的路径是从注册表中读取的。

如果路径实际上是C:Programs File (x86)Program folderexec.exe,则无需转换任何内容。路径已有效。

只有使用字符串文字时才需要双\

例子:

假设您的注册表值包含C:Programs File (x86)Program folderexec.exe逐字记录

程序片段 1:

CString somepath = YourGetFromRegistryFunction();
// now somepath contains the correct path already
AfxMessageBox(somepath);  // show the path for debugging purposes

程序代码段 2:

CString somepath = "C:\Programs File (x86)\Program folder\exec.exe";
// now somepath contains the correct path already, the compiler
// replaces the `\` with a single `\`
AfxMessageBox(somepath);  // show the path for debugging purposes

最新更新