View Full Version: #define

C++ Learning Community > C++ in General > #define


Title: #define
Description: ?


Kylevision - August 13, 2003 06:45 PM (GMT)
Is there a way to do #define so that the thing that it equals isnt one line?

Dragon - August 13, 2003 08:52 PM (GMT)
What do you mean by the "thing it equals"?

Kylevision - August 14, 2003 04:35 AM (GMT)
like this

#define monkey cout<<"Monkey"<<endl;

is there a way to make the cout<<"Monkey"<<endl; part be more then one line?

TheHawgMaster - August 14, 2003 04:45 AM (GMT)
You can use the line-extension operator ( \ ) like this:
CODE
#define cout << \
"Monkey"\
<< endl;

FHCandyman - August 14, 2003 09:58 AM (GMT)
out of curiosity why do you have to use the "\" operator. That doesn't look like code that requires more than one line. Why dont you just press enter to put it on the new line, because I know C++ ignores white space.

dr voodoo - August 14, 2003 01:12 PM (GMT)
I don't really know what you mean but could it be this:
#define monkey cout<<"Monkey1"<<endl<<"Monkey2"<<endl;

Sam Fisher vs Solid Snake - August 14, 2003 02:54 PM (GMT)
i would use
#define Monkey "1"
#define Monkey "2"
std::cout << Monkey1 << std::end1
std::cout << Monkey2 << std::end1

or something like this

TheHawgMaster - August 14, 2003 03:18 PM (GMT)
C++ ignores white-space, and so does the C pre-processor -- except for line-feeds. ALL pre-processor directives must take place on a single line, otherwise the pre-processor would have no idea where the #define ends. The only way to get it onto multiple lines is to extend the single line where the #define takes place.

Sam Fisher vs Solid Snake - August 14, 2003 04:15 PM (GMT)
, This is how my compiler does it, or wants me to do it, same with my book, and it works fine

TheHawgMaster - August 14, 2003 05:25 PM (GMT)
QUOTE

#define Monkey "1"
#define Monkey "2"
std::cout << Monkey1 << std::end1
std::cout << Monkey2 << std::end1

That doesn't make any sense. You never define Monkey1 or Monkey2. Your code would just define Monkey as "2" and then tell you that Monkey1 and 2 are undefined.

dr voodoo - August 14, 2003 07:09 PM (GMT)
CODE
#define Monkey "1"
#define Monkey "2"
std::cout << Monkey1 << std::end1
std::cout << Monkey2 << std::end1

Na that may be some strange VC++ code but it's no standard C++!

TheHawgMaster - August 14, 2003 08:05 PM (GMT)
I use VC++ and I've never seen anything like that. (That worked ;) )




* Hosted for free by InvisionFree