【C/C++ 1】Clion配置与运行C语言 【C/C++ 2】Clion配置与运行C语言
方法一、 在当前项目中建一新项目,把下列文件添中到项目中 主函数map1.cpp,其中添加 #include “map7.h”,
方法二: 在主函数map1.cpp中直接中添加 #include “add.cpp”,#include " sub.cpp",把这三个文件放在同一目录下。参考链接:方法二
我这里示例方法一: 1.
头文件map7.h 声明 map7.ccp中函数int test_map7();
#ifndef MAP_MAP7_H
#define MAP_MAP7_H
int test_map7();
#endif //MAP_MAP7_H
map7.ccp 文件
```cpp
#include "map7.h"
#include <iostream>
using namespace std;
int test_map7(){
int var1;
char var2[10];
cout << "var1变量的地址" << &var1 <<endl;
cout << "var2变量的地址" << &var2 <<endl;
int var =20;//实际变量的声明
int *ip; //指针变量的声明
ip=&var; //在指针变量中存储var的地址
cout<< "value of var variable"<<var <<endl;
//输出在指针变量中存储的地址
cout << "var变量的地址" << &var <<endl;
cout<< "address stored in ip variable:"<< ip<<endl;
// 访问指针中地址de值
cout <<"value of *ip variable:" << *ip <<endl;
}
在map1.cpp中引用
#include<iostream>
#include "map7.h"
using namespace std;
int main() {
cout << "type: \t\t" << "************size**************" << endl;
test_map7();
return 0;
}
在clion中注意要修改CMakeLists.txt, add_executable(map map1.cpp) 中增加引用的函数add_executable(map map1.cpp map7.cpp)
cmake_minimum_required(VERSION 3.14)
project(map)
set(CMAKE_CXX_STANDARD 14)
add_executable(map map1.cpp map7.cpp)