문제

I'm coming to C++ from C#. I have a string with a lot of backslashes in it and I'd like to read the string as raw text. Does C++ have something like C#'s "at string"? For example:

string s = @"\\Some\Path";

In my C++ file I'm using:

#include <string>
도움이 되었습니까?

해결책

You can use raw string literals:

std::string s = R"(\Some\Path)";

This feature is available in C++11.

Note that for file system paths you can use forward slashes:

std::string s = "/Some/Path";

다른 팁

According to the c++11 standard it has raw strings like R"....", I say according to the standard because I have never needed to use them :).
This kind of string can be very useful for things like regexes.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top