Frage

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?

War es hilfreich?

Lösung

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

std::string mypath = "c:/custom/file.jpg";

Andere Tipps

Try a raw string literal:

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

Try to get used of double backslash character, because in c++ all parser and compiler understand that. and if your VS template \\ doublebackslash produce a \ single backslash, use 4 backslash \\\\ to produce \\ doublebackslash correctly.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top