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文件

效果如图

 

 

第二种:编写头文件

。。。弄好在更

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM