Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Character constant ignore

I need to compare variable value with backslash symbol:

char symbol;
/* assigning a value to
a variable */
if (symbol == '\') {
    // some action
}

But my Visual Studio recognizes it as a character constant. How can I ignore it?

Maybe there is a "r" prefix like in python:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

symbol = r'\'

>Solution :

You can use double slashes (\\) or use raw string literals to avoid escaping backslashes.

char symbol;
if (symbol == '\\') {
    // some action
}

or

char symbol;
if (symbol == R"\") {
    // some action
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading