Passing char * that contains the path


I am trying to pass several functions a line with an outline, but each "\\" that I put in the path becomes a single "\" in the inner function, and I cannot use it that way.
Is there a way to save "\\" when entering a new function?
I use C ++ for windows.
thanks:)

+4
source share
2 answers

Be prepared for some confusing answer.

\ is an escape character (for example, you've probably already encountered the escape sequence \n ), and \\ is an escape sequence that represents a single character \ (in a sense, this can be understood as escape of an escape character). If you really want to have \\ in your line, you will need to use \\\\ :

 std::cout << "\\\\something\\" << std::endl; /* prints "\\something\" */ 

To provide another example, suppose you want to have the string " in the string. "

 const char *str = "Hello "World""; 

obviously will not compile, and you will need to escape " with \ :

 const char *str = "Hello \"World\""; 
+13
source

In C ++ 0x, you will have a string literal:

 R"(anything can appear here, even " or \\ )" 

Where everything that is between "(and)" is part of a line - no escaping is required. In the current standard, you cannot achieve what you want.

+2
source

All Articles