在C++中,可以通过以下步骤调用其他文件中的函数:
以下是一个示例:
// other_file.h #ifndef OTHER_FILE_H #define OTHER_FILE_H void otherFunction(); // 声明函数 #endif // other_file.cpp #include "other_file.h" #include <iostream> void otherFunction() { std::cout << "This is the other function." << std::endl; } // main.cpp #include "other_file.h" int main() { // 调用函数 otherFunction(); return 0; } 在上面的示例中,"main.cpp"文件包含了"other_file.h"头文件,并在main函数中调用了"otherFunction"函数。