Anyone know some preprocessor tricks?

I want this program to include the spaces on either size of the text - anyone know a trick to get around this?
1
2
3
4
5
6
7
8
#define EXACTLY(t) #t

int main()
{
	cout << "\"" << EXACTLY(  this is a test  ) << "\"" << endl;
	cin.sync();
	cin.ignore();
}
"this is a test"
#define EXACTLY(t) " "#t" "

(not really a preprocessor trick. String literals concatenate)
Last edited on
I don't mean that I want space around it, I mean that I want it to include whatever spaces, tabs, etc I happen to have on the edge rather than trimming them off.
I don't think that's possible.

Unless you put the whitespace in double quotes, it'll get automatically trimmed.

You could do this (I know it's not ideal):

1
2
3
4
5
6
7
8
#define EXACTLY(A,B,C) A#B C

int main()
{
	cout << "\"" << EXACTLY("  ",this is a test,"  ") << "\"" << endl;
	cin.sync();
	cin.ignore();
}


Or you could make macros for SPACESn(dummy) and TABSn(dummy) (might need to hard-code this or use boost's preprocessor library), and do something like this:

cout << "\""<<SPACES1()TABS3()"this is a test"TABS2()SPACES4()TABS2()<<"\""<< endl;

Please someone correct me if I'm wrong.
Last edited on
I'm pretty sure it can't be done, also.

Besides I don't see what good it would do anyway =P
Well, I have a macro in the SDK I use that takes for letters and makes them into a long ID:
#define MAKEID(a,b,c,d) ((#@a<<24)|(#@b<<16)|(#@c<<8)|(#@d))
I don't fully understand what the @ does (I think it takes it as a character literal instead of a string literal), but my point is that it doesn't work with spaces, tabs, etc. It works perfectly for all other characters. I could assign a numerical ID myself but I was just curious...well, problem solved: it's not possible :)
Topic archived. No new replies allowed.