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 .
-
Remove #include & lt; stdio.h & gt;
It is not needed. -
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]; -
Change to
2.cpp
. Before using it forcallotherfile
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
- Add
# include & lt; Iostream & gt; You need it to use
std :: cout
andstd :: endl
. - Provide a definition of the array.
- Use
cout
andendl
with thestd ::
scope. - Since
var
is an array, usevar.i
instead ofvar [p] .i
. -
Prevent the loop when the loop counter is reached
P
, when it is no more thanp
. Please note that there is not a valid index for an array with elements10
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; }
- Add
Comments
Post a Comment