How to put two backslash in C++

前端 未结 5 1539
北海茫月
北海茫月 2021-01-15 19:48

i need to create a function that will accept a directory path. But in order for the compiler to read backslash in i need to create a function that will make a one backslash

5条回答
  •  -上瘾入骨i
    2021-01-15 19:57

    But in order for the compiler to read backslash in i need to create a function that will make a one backslash into 2 backslash

    The compiler only reads string when you compile, and in that case you will need two as the first back slash will be an escape character. So if you were to have a static path string in code you would have to do something like this:

    std::string path = "C:\\SomeFolder\\SomeTextFile.txt";
    

    The compiler will never actually call your function only compile it. So writing a function like this so the compiler can read a string is not going to solve your problem.

提交回复
热议问题