-1

I need a string that only contains "\". But this doesn't seem to work since (as far as I get it) the compiler sees it as a command instead of a simple string without any meaning.

As you can probably tell, I'm still fairly inexperienced, so aplogies if I'm not that up to speed.

I already tried to use a char, but that also didn't work.

What I want is something like this: std::string mystr = "\";

I get this error message: "A string constant cannot be continued on a second line." Makes sense to me, but doesn't really help me because I'm not even trying to define a string over 2 lines.

Austin
  • 25,759
  • 4
  • 25
  • 48
Nico
  • 21
  • 3

1 Answers1

1

You need to escape the backslash:

std::string mystr = "\\";

Alternatively you can use raw string literals:

std::string mystr = R"(\)";
ruohola
  • 21,987
  • 6
  • 62
  • 97