Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. Trouble with C macro '#'

Trouble with C macro '#'

Scheduled Pinned Locked Moved C / C++ / MFC
helptutorialquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cold_Fearing_Bird
    wrote on last edited by
    #1

    #define MyTemplate( filename ) "D:/Template/MyApp/" # filename #include MyTemplate( stdafx.h ) // failed to compile int main() { cout << MyTmeplate( stdafx.h ) // ok, print "D:/Template/MyApp/stdafx.h" } How to include files in "D:/Template/MyApp/" if I don't copy them to my own project directorie? solution like the macro doesn't work perhaps #include instruction doesn't accept another '#' in its statement. Could someone help me, thanks in advance!

    G M 2 Replies Last reply
    0
    • C Cold_Fearing_Bird

      #define MyTemplate( filename ) "D:/Template/MyApp/" # filename #include MyTemplate( stdafx.h ) // failed to compile int main() { cout << MyTmeplate( stdafx.h ) // ok, print "D:/Template/MyApp/stdafx.h" } How to include files in "D:/Template/MyApp/" if I don't copy them to my own project directorie? solution like the macro doesn't work perhaps #include instruction doesn't accept another '#' in its statement. Could someone help me, thanks in advance!

      G Offline
      G Offline
      Geoff Williams
      wrote on last edited by
      #2

      I recommend you have a look at Token Concatenation[^]. That explains how to define and use a C macro to concatenate tokens.

      1 Reply Last reply
      0
      • C Cold_Fearing_Bird

        #define MyTemplate( filename ) "D:/Template/MyApp/" # filename #include MyTemplate( stdafx.h ) // failed to compile int main() { cout << MyTmeplate( stdafx.h ) // ok, print "D:/Template/MyApp/stdafx.h" } How to include files in "D:/Template/MyApp/" if I don't copy them to my own project directorie? solution like the macro doesn't work perhaps #include instruction doesn't accept another '#' in its statement. Could someone help me, thanks in advance!

        M Offline
        M Offline
        MicroVirus
        wrote on last edited by
        #3

        Considering you're using stdafx.h, I assume you are using Visual Studio? Why not just add the include directory to Additional Include Directories in the Project Properties dialog, under the C/C++ tab. That way, there's no need for possibly troublesome macro's and makes it easier to maintain. For other build environments there should be similar options.

        C 2 Replies Last reply
        0
        • M MicroVirus

          Considering you're using stdafx.h, I assume you are using Visual Studio? Why not just add the include directory to Additional Include Directories in the Project Properties dialog, under the C/C++ tab. That way, there's no need for possibly troublesome macro's and makes it easier to maintain. For other build environments there should be similar options.

          C Offline
          C Offline
          Cold_Fearing_Bird
          wrote on last edited by
          #4

          Thank you. That's a nice solution.

          1 Reply Last reply
          0
          • M MicroVirus

            Considering you're using stdafx.h, I assume you are using Visual Studio? Why not just add the include directory to Additional Include Directories in the Project Properties dialog, under the C/C++ tab. That way, there's no need for possibly troublesome macro's and makes it easier to maintain. For other build environments there should be similar options.

            C Offline
            C Offline
            Cold_Fearing_Bird
            wrote on last edited by
            #5

            I found another trouble, I have to include the D:\template for every individual project. Is it possible to include it like "VC98\include" as an one-time-job ?

            V 1 Reply Last reply
            0
            • C Cold_Fearing_Bird

              I found another trouble, I have to include the D:\template for every individual project. Is it possible to include it like "VC98\include" as an one-time-job ?

              V Offline
              V Offline
              venkatmakam
              wrote on last edited by
              #6

              In vs2005,

              1. Go to Tools->Options
              2. Click on projects and solutions tree item
              3. Select vc++ directories item
              4. Select Include files in drop down window "Show Directories for"
              5. Then add your include directory.

              I think it will be same in all VS IDE.

              http://www.mono-project.com/Main\_Page

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups