Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Double slash // in paths - can I use single slash?

I have a VS template with something like

string mypath = "C:\\custom\\file.jpg";

I'd like to make the C:\custom\ part with a template substitution parameter $userpath$. Is there any way I can avoid using double slashes?

What I'd like to write is:

string mypath = SOMETHING("C:\custom\file.jpg")

that doesn't get escaped with \c and \f and form a valid path. Is it possible?

like image 551
Marco A. Avatar asked Jun 25 '13 17:06

Marco A.


People also ask

Why is there a double slash in path?

Double Backslashes (\\)Two backslashes are used as a prefix to a server name (hostname). For example, \\a5\c\expenses is the path to the EXPENSES folder on the C: drive on server A5. See UNC, \\, path and forward slash.

What is the difference between and \\ in file path?

Windows ignores double backslashes. So while the second syntax with \ is correct and you should use that one, the first with \\ works too. The only exception is double-backslash at the very beginning of a path that indicates a UNC path.

What is the difference between single slash and double slash in Python?

Python has two division operators, a single slash character for classic division and a double-slash for “floor” division (rounds down to nearest whole number). Classic division means that if the operands are both integers, it will perform floor division, while for floating point numbers, it represents true division.

Which slash is used for path?

Windows traditionally uses the backslash ( \ ) to separate directories in file paths. (For example, C:\Program Files\PuppetLabs .)


2 Answers

For paths you should be able to use a single forward slash as a separator:

std::string mypath = "c:/custom/file.jpg";
like image 179
David Rodríguez - dribeas Avatar answered Sep 26 '22 19:09

David Rodríguez - dribeas


Try a raw string literal:

string mypath = R"(C:\custom\file.jpg)";
like image 24
tckmn Avatar answered Sep 24 '22 19:09

tckmn