Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ Error - missing closing quote with \

I am using the define method in C++ with a backslash, in conjunction with an ifstream, which is called a. However, I get an error when using the backslash, which says:

Error - missing closing quote.

I have tried doing #define BACKSLASH \, but that contains no value at all:

#define BACKSLASH '\'

if((char)a.get() == BACKSLASH // Error here)
{
     // BLAH BLAH BLAH
}
like image 757
user2976089 Avatar asked Feb 14 '26 23:02

user2976089


2 Answers

You need to escape it. So either:

#define BACKSLASH '\\'

Or:

if((char)a.get() == '\\')
{
     // BLAH BLAH BLAH
}
like image 144
Roger Rowland Avatar answered Feb 16 '26 12:02

Roger Rowland


Try this:

#define BACKSLASH '\\'

instead of

#define BACKSLASH '\'

ie you need to escape the backslash. Since when '\' means that you are escaping single quote.

like image 31
Rahul Tripathi Avatar answered Feb 16 '26 12:02

Rahul Tripathi



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!