How to use "\" not as a command but just as a text in a string

I am trying to make a graphic in C++ that basically is a smiley face:

"_____/"

But when I build my program, the use of "\" character gives me an error "unknown escape sequence"

Any thoughts? I am going to print the smiley face by printing some special characters.

Upvotes: 0

Views: 107

Answers (3)

TonySalimi
TonySalimi

Reputation: 8427

You can also use raw string literals in C++11 that is more convenient:

std::cout << "The output is: " << R"(\_________/)" << std::endl;

that prints for you something like this:

The output is: \_________/

Upvotes: 0

kemp
kemp

Reputation: 703

You might have to escape the backslash itself. Try using \\.

Upvotes: 5

Shadi Naif
Shadi Naif

Reputation: 184

Use "\\" . The backslash is a string command

"\\" --> \
"\n" --> new line
"\t" --> tab

etc..

See full list here https://msdn.microsoft.com/en-us/library/6aw8xdf2.aspx

Upvotes: 1

Related Questions