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. Using a #include in a struct

Using a #include in a struct

Scheduled Pinned Locked Moved C / C++ / MFC
question
15 Posts 7 Posters 2 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.
  • A Offline
    A Offline
    Anonymous
    wrote on last edited by
    #1

    Hi, I've heard it's possible to do something like this, struct Data myData = { { #include "myData.dat" } } Or something like that... to include information from a file directly into a struct. My question is, what is the proper format for this, and how do I format the file so that it reads in correctly? Let's say my struct has 3 integers and a string, do I then have to have 3 integers and a string on each line of the file, separated by commas or something? Or what? Thanks!

    T M 2 Replies Last reply
    0
    • A Anonymous

      Hi, I've heard it's possible to do something like this, struct Data myData = { { #include "myData.dat" } } Or something like that... to include information from a file directly into a struct. My question is, what is the proper format for this, and how do I format the file so that it reads in correctly? Let's say my struct has 3 integers and a string, do I then have to have 3 integers and a string on each line of the file, separated by commas or something? Or what? Thanks!

      T Offline
      T Offline
      toxcct
      wrote on last edited by
      #2

      the #include preprocessor directive copies the content of the file in parameter at the place it is written. so, your code would work i think. but, i doubt the rounding { } are necessary. however, the content of the myData.dat should be containing a correct C++ code that defines a structure...

      struct Data {
      #include "myData.dat;
      } myData;

      myData.dat :
      private:
      int m_i;
      char m_c;
      public:
      Data();
      ~Data();


      TOXCCT >>> GEII power
      [toxcct][VisualCalc]

      A 1 Reply Last reply
      0
      • A Anonymous

        Hi, I've heard it's possible to do something like this, struct Data myData = { { #include "myData.dat" } } Or something like that... to include information from a file directly into a struct. My question is, what is the proper format for this, and how do I format the file so that it reads in correctly? Let's say my struct has 3 integers and a string, do I then have to have 3 integers and a string on each line of the file, separated by commas or something? Or what? Thanks!

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

        IMO, anyone coding like that should be fired.


        Maximilien Lincourt Your Head A Splode - Strong Bad

        T A X K 4 Replies Last reply
        0
        • M Maximilien

          IMO, anyone coding like that should be fired.


          Maximilien Lincourt Your Head A Splode - Strong Bad

          T Offline
          T Offline
          toxcct
          wrote on last edited by
          #4

          Maximilien wrote: anyone coding like that should be fired yes... of course ! actually, i don't really understand the point why he tries to code this way ; i just answered consequently...


          TOXCCT >>> GEII power
          [toxcct][VisualCalc]

          1 Reply Last reply
          0
          • M Maximilien

            IMO, anyone coding like that should be fired.


            Maximilien Lincourt Your Head A Splode - Strong Bad

            A Offline
            A Offline
            Anonymous
            wrote on last edited by
            #5

            Using that method was my directive. If you understood the context and objectives you might see things differently. I can't talk about it since it's a military system.

            T B 2 Replies Last reply
            0
            • T toxcct

              the #include preprocessor directive copies the content of the file in parameter at the place it is written. so, your code would work i think. but, i doubt the rounding { } are necessary. however, the content of the myData.dat should be containing a correct C++ code that defines a structure...

              struct Data {
              #include "myData.dat;
              } myData;

              myData.dat :
              private:
              int m_i;
              char m_c;
              public:
              Data();
              ~Data();


              TOXCCT >>> GEII power
              [toxcct][VisualCalc]

              A Offline
              A Offline
              Anonymous
              wrote on last edited by
              #6

              Right, actually what I need is the information to be included in a struct array rather than the struct definition itself, but the same principle should apply. Thank you.

              1 Reply Last reply
              0
              • A Anonymous

                Using that method was my directive. If you understood the context and objectives you might see things differently. I can't talk about it since it's a military system.

                T Offline
                T Offline
                toxcct
                wrote on last edited by
                #7

                :zzz::zzz::zzz: i didn't see anything, i didn't heared anything... ... and you already told too much (we don't need to know you work on a confidential project or not)... :suss:


                TOXCCT >>> GEII power
                [toxcct][VisualCalc]

                1 Reply Last reply
                0
                • M Maximilien

                  IMO, anyone coding like that should be fired.


                  Maximilien Lincourt Your Head A Splode - Strong Bad

                  X Offline
                  X Offline
                  XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
                  wrote on last edited by
                  #8

                  Maximilien wrote: IMO, anyone coding like that should be fired. No, it's sometimes (rarely) necessary for large table structures.

                  B K 2 Replies Last reply
                  0
                  • X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

                    Maximilien wrote: IMO, anyone coding like that should be fired. No, it's sometimes (rarely) necessary for large table structures.

                    B Offline
                    B Offline
                    Bob Stanneveld
                    wrote on last edited by
                    #9

                    It's not necessary to do such horrible things. Especially for large table structures! If you have a very large table structure, one should redesign the class into smaller reusable classes and create a utility that combines the functionality. Thats one demand for a good design. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                    A 1 Reply Last reply
                    0
                    • A Anonymous

                      Using that method was my directive. If you understood the context and objectives you might see things differently. I can't talk about it since it's a military system.

                      B Offline
                      B Offline
                      Bob Stanneveld
                      wrote on last edited by
                      #10

                      Software is software. You have good and solid software designs and bad software designs. Anyone who designs software like that, should go to school again. Any programmer who doesn't complain about such IMHO horrible design should go to school with the designer... Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                      L 1 Reply Last reply
                      0
                      • M Maximilien

                        IMO, anyone coding like that should be fired.


                        Maximilien Lincourt Your Head A Splode - Strong Bad

                        K Offline
                        K Offline
                        knapak
                        wrote on last edited by
                        #11

                        Hi Sorry to interfere with this discussion. As a novice programmer, I come to this boards to ask for advice about things that I don't know or don't understand. Very often I get invaluable help but unfortunately also very often I only get replies like this... "That would never work"... "Anyone coding like this should be fired"... etc etc etc. If we come to ask a question is not because we are stupid but because we don't have the knowledge, and actually whoever claims that he or she knows everything about C, C++, C#, etc. and is infallible MUST actually be fired. Bottom line, if you want to help, make constructive comments, explain why things would work or wouldn't, provide sample code and refrain yourself from the impulse to riducule those who know less than you... there's always someone out there that knows more than you. Cheers Carlos

                        1 Reply Last reply
                        0
                        • X XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

                          Maximilien wrote: IMO, anyone coding like that should be fired. No, it's sometimes (rarely) necessary for large table structures.

                          K Offline
                          K Offline
                          knapak
                          wrote on last edited by
                          #12

                          Thank you for your response, this certainly proves that there's always someone who knows more that can shame those arrogants that mocked those who knew less... great lesson.

                          1 Reply Last reply
                          0
                          • B Bob Stanneveld

                            It's not necessary to do such horrible things. Especially for large table structures! If you have a very large table structure, one should redesign the class into smaller reusable classes and create a utility that combines the functionality. Thats one demand for a good design. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                            A Offline
                            A Offline
                            Anonymous
                            wrote on last edited by
                            #13

                            The simple fact that you would criticize the code, designer, and developer without knowing the context is laughable. This code is necessary in this case. I have never used it before, but it is the only way to meet all the requirements for this piece of software at this time. Anyone who thinks this type of design is never necessary is clearly not experienced in a wide enough variety of software to have been required to use it before. Your comments are rude, uncalled for, and altogether ignorant. Get your facts together, all of you in this thread who are criticizing, get your facts together before you jump on someone's case about a software system that you have no knowledge of whatsoever. If you have nothing useful to say, then say nothing. I have been asking and answering questions on this BBS for years, and I've never seen such unbased arrogance here before. I hope to never see it again.

                            B 1 Reply Last reply
                            0
                            • B Bob Stanneveld

                              Software is software. You have good and solid software designs and bad software designs. Anyone who designs software like that, should go to school again. Any programmer who doesn't complain about such IMHO horrible design should go to school with the designer... Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                              L Offline
                              L Offline
                              Lost User
                              wrote on last edited by
                              #14

                              Thank you for helping to perpetuate the belief that all computer scientists are elitist and arrogant and jump to conclusions about others' intelligence and skills based on their own lacking information and experience. Anyway... to the original poster: You're including actual data with this design, right? You're not trying to include compiled code from another file? It's basically just a data table that you have as an external file?

                              1 Reply Last reply
                              0
                              • A Anonymous

                                The simple fact that you would criticize the code, designer, and developer without knowing the context is laughable. This code is necessary in this case. I have never used it before, but it is the only way to meet all the requirements for this piece of software at this time. Anyone who thinks this type of design is never necessary is clearly not experienced in a wide enough variety of software to have been required to use it before. Your comments are rude, uncalled for, and altogether ignorant. Get your facts together, all of you in this thread who are criticizing, get your facts together before you jump on someone's case about a software system that you have no knowledge of whatsoever. If you have nothing useful to say, then say nothing. I have been asking and answering questions on this BBS for years, and I've never seen such unbased arrogance here before. I hope to never see it again.

                                B Offline
                                B Offline
                                Bob Stanneveld
                                wrote on last edited by
                                #15

                                Hello, I apologize for my rudeness. Indeed, should not critisize people I don't know on something I don't understand. I have experiance in including stuff at places where it shouldn't be included. I once had to hide some details that I included. One solution was to create a "private" namespace and include the header there, which was the most horrible mistake I ever made. Not only did it not solve my problems, but it created many more. Bad maintanability is one, lot's of compiler errors are another. After giving it some more thought, I insulated the details from the physical interface and I included the file in the source file, not the header. I know that there are many solutions to one problem, and that one solution is always better than another. I also don't know what you are trying to achieve, but since you know that it can be done, I hope that you are happy with the solution. Again, I apologize for my rude post. Behind every great black man...             ... is the police. - Conspiracy brother Blog[^]

                                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