将路径符号更改为/
Change path symbols to /
我有一个要执行的文件的字符串路径。例如:
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(), '', '/');
相关文章:
- 在C++中,将大的无符号浮点数四舍五入为整数的最佳方法是什么
- 有符号的int和int-有没有一种方法可以在C++中区分它们
- 将无符号char*转换为std::istream*C++
- 如何在C++中将一个无符号的 int 转换为两个无符号的短裤?
- 如何将更多文件夹添加到c++include路径
- 带有特殊路径部分的"std::filesystem::weakly_canonical"失败
- vscode g++链路故障:体系结构x86_64的未定义符号
- C++A*算法并不总是在路径中具有目标节点
- 从矢量<无符号字符>转换为字符* 包括垃圾数据
- 如何理解将半精度指针转换为无符号长指针和相关的内存对齐
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 使用gcc从静态链接的文件中查找可选符号
- C++和带有国家符号的文件路径(也许用 UTF8 编码)
- 函数路径追加上未解决的外部符号错误
- 在可执行文件中使用带有符号链接的相对路径
- 将路径符号更改为/
- 如何避免iOS二进制文件中的符号和源路径
- 在目录路径中使用外壳符号
- 如何通过.props文件设置调试符号路径
- 如何确定符号链接指向的文件的路径