macro to print a string
How the PLUS macro work if i pass two strings to it, and it will parse them as the enum value? Thanks in advance. Sorry that i can't express myself too clearly.
#include "stdio.h" #include <string> #include <iostream> using namespace std; #define PRINT(Y) #Y #define PLUS(X, Y) X+Y int main( int argc, char *argv[] ) { typedef enum { FIRST, SECOND, THIRD }; const char *a="THIRD", *b="SECOND"; cout << PRINT(THIRD+SECOND is: ) << PLUS(a, b) << endl; return 0; }
Answers
I think, from your followup comment, that I understand better what you're trying to do: Trying to make both a string form and non-string form of a symbol such as an enum value.
The way I usually do this is as follows:
#define Q(x) QQ(x) #define QQ(x) #x
Then you use it with a non-string value, such as an enum:
enum { FRED = 1, BARNEY = 2 }; int main() { std::cout << "The enum " << Q( FRED ) << " has the value " << FRED << std::endl; std::cout << "The enum " << Q( BARNEY ) << " has the value " << BARNEY << std::endl; }
This prints:
The enum FRED has the value 1 The enum BARNEY has the value 2
If that's not what you're trying to accomplish, please clarify in your question and leave me a comment.
Need Your Help
Tomcat v7.0 Server setup for ports 8086 and 8009
java eclipse installation port tomcat7I am new in java programming. I have write a small web program using struts. I ve already install apche tomcat 7 server. I configure this server to my project. Tomcat server error showing When I ru...