在路径中双斜杠// - 我可以使用单斜杠吗?

Mar*_* A. 5 c++ visual-studio visual-studio-templates

我有一个类似的VS模板

string mypath = "C:\\custom\\file.jpg";
Run Code Online (Sandbox Code Playgroud)

我想用模板替换参数$ userpath $创建C:\ custom\part.有什么办法可以避免使用双斜线吗?

我想写的是:

string mypath = SOMETHING("C:\custom\file.jpg")
Run Code Online (Sandbox Code Playgroud)

不会使用\ c和\ f进行转义并形成有效路径.可能吗?

Dav*_*eas 7

对于路径,您应该能够使用单个斜杠作为分隔符:

std::string mypath = "c:/custom/file.jpg";
Run Code Online (Sandbox Code Playgroud)


Doo*_*nob 5

尝试使用原始字符串文字:

string mypath = R"(C:\custom\file.jpg)";
Run Code Online (Sandbox Code Playgroud)