C/C++之Exercise

时间:2023-03-08 17:43:51
C/C++之Exercise

一.C/C++之初学Demo---C++调用C.h文件使用实例:

工程结构:

C/C++之Exercise

exercise.h code:

 #ifndef _EXERCISE_H_
#define _EXERCISE_H_
#include <externcpp.h>;
extern "C"
{
#include <externc.h>;
}
#endif

externc.h code:

 #ifndef _EXTERNC_H_
#define _EXTERNC_H_
#include <stdio.h>; void c_hello(); #endif

externcpp.h code:

 #ifndef _EXTERNCPP_H_
#define _EXTERNCPP_H_
#include <iostream>;
using namespace std; void cpp_hello(); #endif

c_hello.c code:

 #include <externc.h>;

 void c_hello(){
printf("C Hello World!");
getchar();
}

cpp_hello.cpp code:

 #include <externcpp.h>;

 void cpp_hello(){
cout<<"C++ Hello World!";
getchar();
}

main.cpp code:

 #include <exercise.h>

 void main(){
c_hello();
cpp_hello();
}

二.VS2010及以上之错误C1083解决:

"error C1083"这个错误是因为VS中C/C++常规配置中加载头文件的路径问题:

解决方法:

1)右键查看该项目的属性

2)点击属性——〉配置属性  ——〉C/C++  ——〉  常规  ——〉附加包含目录 ——〉编辑

3) 添加

$(ProjectDir) // 工程目录

$(ProjectDir)inc // 工程子目录