How can I get past this errer "# is not followed by a macro perimeter on line:
#define ASSERT(x) \
I copied this straight out of my book can anyone show me how I can get it to work thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
    #define DEBUG
#include<iostream>
#ifndef DEBUG
    #define ASSERT(x)
#else
    #define ASSERT(x) \
#if(! (x)) \
    std::cout <<"Error! Assert " << #x << " falied \n"; \
    std::cout << " on line " <<__LINE__<< "\n"; \
    std::cout << " in file " <<__FILE__<< "\n" \
#endif
int main()
    int x =5;
    std::cout<<"First assert: \n";
    ASSERT (x==5);
    std::cout<<"\nSecond assert: \n";
    ASSERT (x !=5);
    std::cout <<"\nDone.\n";
I looked on stack exchange and it said I can't use ifndef in that order so I changed it to this(see below) but then my errror messages dont fire/ Whats going on, I want to be able to check the x condition with the assert and get the error messages . Please help thanks.
#ifndef DEBUG
#define ASSERT(x)
#define DEBUG
#include<iostream>
#else
#define ASSERT(x) \
#if(! (x)) \
std::cout <<"Error! Assert " << #x << " falied \n"; \
std::cout << " on line " <<__LINE__<< "\n"; \
std::cout << " in file " <<__FILE__<< "\n" \
#endif
int main()
int x =6;
std::cout<<"First assert: \n";
ASSERT (x==5);
std::cout<<"\nSecond assert: \n";
ASSERT (x !=5);
std::cout <<"\nDone.\n";
std::cout <<"Error! Assert " << #x << " falied \n"; \
std::cout << " on line " <<__LINE__<< "\n"; \
std::cout << " in file " <<__FILE__<< "\n" \
#endif
int main()
int x =5;
std::cout<<"First assert: \n";
ASSERT (x==5);
std::cout<<"\nSecond assert: \n";
ASSERT (x !=5);
std::cout <<"\nDone.\n";
hi this does compile on my system but the error messages don't appear. please help me make the error messages appear. Sorry for posting without the tags before thanks.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#include<iostream>
#ifndef DEBUG
#define ASSERT(x)
#define DEBUG
#else
#define ASSERT(x) \
if(! (x)) \
    std::cout <<"Error! Assert " << #x << " falied \n"; \
    std::cout << " on line " <<__LINE__<< "\n"; \
    std::cout << " in file " <<__FILE__<< "\n" \
#endif
int main()
    int x =5;
    std::cout<<"First assert: \n";
    ASSERT (x==5);
    std::cout<<"\nSecond assert: \n";
    ASSERT (x !=5);
    std::cout <<"\nDone.\n";
How can it compile if it's missing the backslash at the end of line 11? And the semicolon before the backslash on line 14?
Do you know what "compile" means?
Also, you defined DEBUG in the wrong place. Think, man! Last edited on