user2976089
user2976089

Reputation: 355

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
}

Upvotes: 2

Views: 12157

Answers (3)

Trần Hiệp
Trần Hiệp

Reputation: 101

Try this:

cout << "\/";

or

cout << "\\";

Upvotes: 0

Rahul Tripathi
Rahul Tripathi

Reputation: 172448

Try this:

#define BACKSLASH '\\'

instead of

#define BACKSLASH '\'

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

Upvotes: 4

Roger Rowland
Roger Rowland

Reputation: 26259

You need to escape it. So either:

#define BACKSLASH '\\'

Or:

if((char)a.get() == '\\')
{
     // BLAH BLAH BLAH
}

Upvotes: 5

Related Questions