I'm trying to see if a character c
equals \
if (c == '\')
//do something
I don't know exactly how this is called but everything after \ turns in a character string.
Use strcmp() to compare strings. The return value is 0 if strings are the same. The return value from strcmp() also indicates order: the value is < 0 or > 0 to indicate which string is lesser or greater.
Yes, char is just like any other primitive type, you can just compare them by == .
Backslash is used as the escape character in C++, as it is in many other languages. If you want a literal backslash, you need to use \\
:
if (c == '\\') {
}
\
backslash is an escape character.
Escape sequences are used to represent certain special characters within string literals and character literals. Read here
So you should do:
if (c == '\\'){
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With