如何在C++中转义白色字符
How to escape white characters in C++
我试图使用 c++ 中的 system 关键字将文件复制到另一个文件夹,只要它不包含白色字符就可以正常工作
那么如何使"修复此问题"文件复制而没有错误呢?
#include <windows.h>
using namespace std;
void trial(){
//*"fix this" is the file's name that I want to copy*
system("copy fix this C:\users\public\");
system("pause");
}
C++与此
几乎没有关系。您的问题是如何将空格转义为输入到 Windows CMD 外壳的命令中;一般来说,这个问题是不平凡的,但在这种情况下,你可以简单地用双引号将文件名括起来,而双引号又必须像在C++字符串文本中一样进行转义:
system("copy "fix this" C:\users\public\");
话虽如此,调用 shell 来复制文件是没有意义的 - 您必须处理转义、错误报告、生成外部进程以获得已经可以从C++完成的事情。
鉴于您已经处于不可移植的区域(您的 cmd 命令.exe不能移植到其他 shell),您可以使用 CopyFile
API:
if(!CopyFile("fix this", "c:\users\public\fix this", TRUE)) {
std::cout<<"Couldn't copy filen";
}
此外,从 C++17 开始,终于有一种标准的、可移植的方法来复制文件。
使用双引号表示路径、copy "this is long path with spaces"
或system("copy "this is long path with spaces"");
相关文章:
- 如何用转义符替换字符串中的所有特殊字符
- Opengl 3.1 GLSL 140 在 C++ 年输出白色在片段着色器中
- 如何在C++中将 Python 字符串转换为其转义版本?
- 如何在C++中用'\'替换''来处理转义序列?
- 如何解释C++字符串中的 \u 转义码?
- PostgresSQL - SQL Ready 语句与字符串转义,防止 SQL 注入攻击
- SFML白色矩形
- 帧缓冲纹理变为白色(片段着色器不会影响它)
- 有没有办法获取用户操作系统的ANSI转义码?
- 是否可以在原始字符串文本中插入转义序列?
- 为什么当我从 cin 阅读时转义字符不起作用?
- 如何在SDL2窗口上使用Cairo绘制一条白色直线
- 使用无法适应其相关类型的转义序列
- 为什么在使用VK_PRESENT_MODE_FIFO_KHR呈现模式调整交换链图像大小时出现白色闪烁
- 转义std::字符串中的特殊字符
- 我可以转义(抑制)C预处理器宏扩展吗
- C++二进制值的转义序列
- OpenGL 混合会在纹理周围创建白色边框
- 如何使白色透明
- 如何在C++中转义白色字符