hello.h

#include<stdio.h>
#ifndef _STDIO_H_
#define _STDIO_H_

void hello();

#endif

hello.cpp
实现hello.h

#include"hello.h"
#include<stdio.h>
void hello()
{
    printf("hello world");
}

t.cpp

#include"hello.h"
int main()
{
    hello();
}

vscode直接运行会报错
在这里插入图片描述

使用
gcc -o t.cpp hello.cpp
把两个文件链接在一起,
.\t
就可以运行了。
在这里插入图片描述

在这里插入图片描述
不要使用vscode的运行按钮来运行,输入命令来运行即可。

玩linux之后,确实喜欢通过输入命令来编译和运行来着。

Logo

腾讯云面向开发者汇聚海量精品云计算使用和开发经验,营造开放的云计算技术生态圈。

更多推荐