標籤:
一.C/C++之初學Demo、C++調用C、.h檔案使用執行個體:
工程結構:
exercise.h code:
1 #ifndef _EXERCISE_H_2 #define _EXERCISE_H_3 #include <externcpp.h>;4 extern "C" 5 { 6 #include <externc.h>;7 }8 #endif
externc.h code:
1 #ifndef _EXTENC_H_2 #define _EXTENC_H_3 #include <stdio.h>;4 5 void c_hello();6 7 #endif
externcpp.h code:
1 #ifndef _EXTERNCPP_H_2 #define _EXTERNCPP_H_3 #include <iostream>;4 using namespace std;5 6 void cpp_hello();7 8 #endif
c_hello.c code:
1 #include <externc.h>;2 3 void c_hello(){4 printf("C Hello World!");5 getchar();6 }
cpp_hello.cpp code:
1 #include <externcpp.h>;2 3 void cpp_hello(){4 cout<<"C++ Hello World!";5 getchar();6 }
main.cpp code:
1 #include <exercise.h>2 3 void main(){4 c_hello();5 cpp_hello();6 }
二.VS2010及以上之錯誤C1083解決:
"error C1083"這個錯誤是因為VS中C/C++常規配置中載入標頭檔的路徑問題:
解決方案:
1)右鍵查看該項目的屬性
2)點擊屬性——〉配置屬性 ——〉C/C++ ——〉 常規 ——〉附加元件封裝含目錄 ——〉編輯
3) 添加
$(ProjectDir) // 工程目錄
$(ProjectDir)inc // 工程子目錄
C/C++之Exercise