0
点赞
收藏
分享

微信扫一扫

c++ 调用 c语言

惠特曼 2022-07-27 阅读 208


mian 文件

#include <iostream>
#include"test.h"

using namespace std;

//在C++中想调用C中的函数

//extern "C" void show(); //一个一个函数调用的方法

int main()
{
show();

return 0;
}

test.h 文件

(头文件把c语言函数包到宏里面,头文件 #include <stdio.h>可以放进去,也可以拿出来)

#ifndef
#define

#include <stdio.h>
//加上下面这段话


#ifdef
extern "C" {
#endif// __cplusplus


void show();


#ifdef
}
#endif// __cplusplus

test.c

#include<stdio.h>
#include "test.h"

//函数的具体实现

void show()
{
printf("Hello world!\n");
}


举报

相关推荐

0 条评论