# Error in code

This topic is 2351 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I was copying the code from a book about using #undef. This is the code:

#define DemoVersion #define DOS_VERSION 5 #include <iostream> using namespace std; int main() { cout << "Checking on the definitions of DemoVersion, DEMO_VERSION_and WINDOWS_VERSION...\n"; #ifdef DemoVersion cout << "DemoVersion defined.\n"; #else cout << "DemoVersion not defined!\n"; #endif #ifndef DOC_VERSION cout << "DOS_VERSION not defined.\n"; #else cout << "DOS_VERSION defined as: " << DOS_VERSION << endl; #endif #ifdef WINDOWS_VERSION cout << "WINDOWS_VERSION defined.\n"; #else cout << "WINDOWS_VERSION not defined!\n"; #endif #undef DOS_VERSION #ifdef DemoVersion cout << "DemeVersion defined.\n"; #else cout << "DemoVersion not defined!\n"; #endif #ifndef DOS_VERSION cout << "DOS_VERSION not defined!\n"; #else cout << "DOS_VERSION defined as: " << DOS_VERSION << endl; #endif #if_Tz'WINDOWS_VERSION ------------------------------------------------------------------------------------------------------- cout << "WINDOWS_VERSION defined.\n"; #else cout << "WINDOWS_VERSION was not defined!\n"; #endif cout << "Done.\n"; return 0; } 

When I compiled the program it gave me an error on the line that is filled with lines. the error is:

- 47 error: invalid preprocessing directive #if_Tz

- 47 warning: missing terminating ' character

- 50 error: #else without #if

- 52 error: #endif without #if

(I figured the last two error are due to the other two and therefore aren't that important since they will solve themselves when the first error is corrected, but I posted them anyway in case I'm wrong.)

I've copied the code exactly the way it is in the book.
Can anyone tell me what the problem is?

##### Share on other sites

 #if_Tz'WINDOWS_VERSION ------------------------------------------------------------------------------------------------------- cout << "WINDOWS_VERSION defined.\n"; 

That line is the problem, it looks like you may have held down a key on accident and typed a bunch of _ in there or maybe the code on the CD was bad =)
it should be:
 #ifdef WINDOWS_VERSION cout << "WINDOWS_VERSION defined.\n"; 

edit: fixed my code error =)