c++ - How to access array of structure in another file -


How to access an array of structures in another file. I have 3 files 1.h 2.cpp 3.cpp is down

1.h

  # include & lt; Stdio.h & gt; Struct st {Int i; Four f [10]; }; Straight Street Verb [10];  

2.cpp

  #include "1.h" int main {int s; // Here I hve scannd value of IRM user callotherfile (); }  

i 3.cpp

  #include "1.h int p; zero callotherfile (zero) {for (p = 1; p & lt ; = 10; P ++) COAT & lt; & lt; var.i [P]  

Here are the P and S class types, please help me fix it

I G ++ 2.COP 3.QP

1.hpp .

  1. Remove #include & lt; stdio.h & gt; It is not needed.
  2. An announcement for the array Provide no definition.

    St {int i; // You were int, not int. I think this typo was described [10];}; external straight string [10];
  3. Change to 2.cpp . Before using it for callotherfile Provide an announcement.

      #include "1.h" zero callphrase (zero); int main () {int s; // This is an unused variable it can be removed from callotherfile (); // You had: No; Change in  3.cpp  

    1. Add # include & lt; Iostream & gt; You need it to use std :: cout and std :: endl .
    2. Provide a definition of the array.
    3. Use cout and endl with the std :: scope.
    4. Since var is an array, use var.i instead of var [p] .i .
    5. Prevent the loop when the loop counter is reached P , when it is no more than p . Please note that there is not a valid index for an array with elements 10 10 .

        #include & lt; Iostream & gt; #include "1.h" Structural St [10]; Int p; // This variable can be shifted to the scope of the scope. Void callotherfile (zero) {for (p = 1; p & lt; 10; p ++) // You have the p & lt; = 10 std :: cout & lt; & Lt; Var [p] .i & lt; & Lt; Std :: endl; }  

Comments

Popular posts from this blog

java - Can't add JTree to JPanel of a JInternalFrame -

javascript - data.match(var) not working it seems -

javascript - How can I pause a jQuery .each() loop, while waiting for user input? -