C++ pass variable from .cpp to header file
问题 this relates to a question i asked previously: C++ array in header file in the main.cpp file there is a variable called fin1 ifstream fin1("ACW2_data.txt"); this might be a stupid question, but how can i use the value of this variable from main.cpp in the header file? (ie. is there a way to pass variables between the two files?) any other info about using header files may help Thanks in advance 回答1: This variable can be declared in the header file as an extern . extern ifstream fin1; Now you