C++引用外部文件

第一种:编写cpp文件,在另一个cpp文件引用cpp文件,调用该文件的函数

例:

  a.编写a.cpp文件

1 #include<string>
2 #include<iostream>
3 using namespace std;
4 void message(string str){
5     cout << str;
6 }

  b.编写b.cpp文件,使用include引用a.cpp文件

#include<string.h>
//引入a.cpp文件
#include "a.cpp"
int main(){
    string str ="Hello,World!";
//    调用a.cpp文件的message函数
    message(str);
    return 0;
}

  c.编译运行b.cpp文件

效果如图

 

 

第二种:编写头文件

。。。弄好在更

 

posted @ 2020-09-22 22:33  从心不欲  阅读(5823)  评论(0)    收藏  举报