将路径符号更改为/

Change path symbols to /

本文关键字:路径 符号      更新时间:2023-10-16

我有一个要执行的文件的字符串路径。例如:

E:folderAfolderBmyfile.exe

若我写下这个路径,并尝试在那里执行文件,它会说那个文件不存在。

当我这样写的时候。然后它就起作用了。

  E:/folderA/folderB/myFile.exe

如何将\更改为/?

Windows对接受Unix(/)还是Windows(\)分隔符有点奇怪。

您还需要在字符串中转义"\"

const char * bad = "C:helloworld.txt"
const char *good = "C:\hello\world.txt"

std::string::replace允许替换。

您可以只使用这个:

std::string str=R"(E:folderAfolderBmyfile.exe)";

一切都会好起来的

实时演示

GetTempPathA(MAX_PATH, tempPath);
string fullPath = (string)tempPath + "/" + data.fileName;
std::replace(fullPath.begin(), fullPath.end(), '', '/');