0

There are posts on the forum describing how to go about making such macros, but I already know that, and I want to do it in another file, which they do not describe how to do.

Therefore, my question is - I'm going to make a program which will use a lot of replacement macros, and I therefore want them to be in another file(s), so that I have file1.cpp and every occurance of "cucumber" is replaced with "banana" using a #define macro in file2.h (I suppose it would have to be a header file?).

THE MACRO I MEAN IS: #define identifier substitution_text which will then replace every identifier with substitutuion text.

Cheers, Matt

πάντα ῥεῖ
  • 1
  • 13
  • 116
  • 190
  • 6
    Please do not use lots of replacement macros. Makes the code harder to read, harder to debug and harder to maintain – Ed Heal Mar 11 '16 at 17:31
  • 3
    And if you *do* use macros, at least use the long-established convention of making them all upper case. – Mark Ransom Mar 11 '16 at 17:35
  • I would also recommend learning C++ from a coherent source like a book (The C++ Programming Language in particular) or a tutorial. Pulling bits and pieces from around stackoverflow, especially with a large, complex language like C++ is bound to lead you down rabbit holes that can easily be avoided. – Cogwheel Mar 11 '16 at 20:20

2 Answers2

1

#include is what you're after.

http://en.cppreference.com/w/cpp/preprocessor/include

But you probably are asking for the wrong tool for the job. Using macros like this is quite broadly frowned upon, and with good reason. If you describe what you're actually trying to do instead of how you're doing it, the answers will be a lot more helpful in the long run.

Community
  • 1
  • 1
Cogwheel
  • 22,781
  • 4
  • 49
  • 67
0

Yeah, I figured it out. I did it the way I thought was the way to do it and it worked. For anyone wondering, I did the #define in a header file, and then #include-d it into the origilnal.