Hiho,
I'm going to do something like this
#define INSPECT( FILENAME,) \
ofstream FILENAME("FILENAME.out");\
For example, I want "INSPECT(abc)" open a file with name "abc.out",
the file object's name is "abc".
I tried the following code, but it still doesn't work.
#define INSPECT( FILENAME,) \
ofstream FILENAME("##FILENAME.out##");\
Last time I checked, ofstream was not in the C language...
So, this code will not compile, but the C preprocessor
will do what you want it to:
#define STRINGIZE(s) # s
#define XSTR(s) STRINGIZE(s)
#define INSPECT(file) \
ofstream (file)(XSTR(file) ".out")
int main (void)
{
INSPECT(test);
return 0;
}
Note: the string part becomes
"test" ".out"
which will be seen as "test.out" by the compiler.
The preprocessor output of
INSPECT(test);
is
ofstream (test)("test" ".out");
If the additional set of parentheses around test
gives you problems, then leave them out after understanding
what that means.
--Michael