Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Create raw text string in C++, analogous to C#'s "@ string"

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>
like image 864
Justin R. Avatar asked Feb 27 '26 18:02

Justin R.


1 Answers

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";
like image 158
juanchopanza Avatar answered Mar 01 '26 10:03

juanchopanza



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!