1、创建头文件和源文件

touch /tmp/tools.h

touch /tmp/main.cpp

 

2、各文件的内容如下:

tools.h

#include<iostream>

void print_hello_world()
{
    std::cout<<"hello world ..."<<std::endl;    
}

main.cpp

#include<iostream>
#include<cstdlib>
#include "tools.h"  // 和引入标准库不同这个要加.h

int main()
{
    print_hello_world();
    return 0;


}

 

3、编译运行:

[root@workstudio tmp]# g++ -o main main.cpp
[root@workstudio tmp]# ./main
hello world ...

相关文章:

  • 2022-12-23
  • 2021-07-06
  • 2021-12-01
  • 2022-01-14
  • 2021-05-22
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-25
  • 2022-12-23
  • 2021-11-22
相关资源
相似解决方案