Define std::string in C++ without escape characters

后端 未结 3 709
星月不相逢
星月不相逢 2020-12-06 10:43

What would be the most painless way to input un-escaped characters sequence to std::string?

Instead of

 std::string st = \"C:\\\\program         


        
相关标签:
3条回答
  • 2020-12-06 10:58

    C & C++ only supports using \ to escape strings, and you have to use it. If you have a bunch of paths to work with, I'd suggest opening them in an editor and doing a bulk replacement of \ with \\.

    0 讨论(0)
  • 2020-12-06 11:05

    For filenames, just use (forward? back?) the other direction slash. It works on Windows too:

    std::string st = "C:/program files/myFile.txt";
    
    0 讨论(0)
  • 2020-12-06 11:12

    You can do it with C++11 raw string literals:

    std::string st = R"(C:\program files\myFile.txt)";
    
    0 讨论(0)
提交回复
热议问题