当前位置:网站首页>【C/C++ 2】Clion配置与运行C语言
【C/C++ 2】Clion配置与运行C语言
2020-11-06 01:22:00 【IT界的小小小学生】
【C/C++ 1】Clion配置与运行C语言
【C/C++ 2】Clion配置与运行C语言
一、C++调用外部文件中的函数(clion)
方法一、 在当前项目中建一新项目,把下列文件添中到项目中
主函数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)
Terminal vim c++程序
vim编写C、C++程序过程(以hello world为例):
1、vim hello.c/hello.cpp。
创建hello.c/hello.cpp文件,并进入vim界面;
2、键入i,进入输入模式。
3、编写hello.c/hello.cpp程序。
4、先按Esc键,退出输入模式,:wq (按Shift+:键,进入命令模式。输入wq),保存并退出。
5、编译hello.c/hello.cpp。
5.1、对于C程序:用gcc hello.c便可编译;
5.2、对于C++程序:用g++ hello.cpp可编译。编译后,均生成a.out的可执行文件;
6、键入指令"./a.out",运行程序。
7、在Terminal上显示"hello world"即成功。
版权声明
本文为[IT界的小小小学生]所创,转载请带上原文链接,感谢
https://vip01.blog.csdn.net/article/details/106386452
边栏推荐
- 向北京集结!OpenI/O 2020启智开发者大会进入倒计时
- 用Keras LSTM构建编码器-解码器模型
- 我们编写 React 组件的最佳实践
- [译] 5个Vuex插件,给你的下个VueJS项目
- 大数据应用的重要性体现在方方面面
- PLC模拟量输入和数字量输入是什么
- 小白量化投资交易入门课(python入门金融分析)
- 车的换道检测
- Technical director, to just graduated programmers a word - do a good job in small things, can achieve great things
- Pattern matching: The gestalt approach一种序列的文本相似度方法
猜你喜欢
DRF JWT authentication module and self customization
Didi elasticsearch cluster cross version upgrade and platform reconfiguration
(1)ASP.NET Core3.1 Ocelot介紹
How to demote a domain controller in Windows Server 2012 and later
Using Es5 to realize the class of ES6
读取、创建和运行多个文件的3个Python技巧
免费的专利下载教程(知网、espacenet强强联合)
Jmeter——ForEach Controller&Loop Controller
阿里云Q2营收破纪录背后,云的打开方式正在重塑
Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
随机推荐
7.3.1 file upload and zero XML registration interceptor
7.2.1 cache configuration of static resources
hadoop 命令总结
对pandas 数据进行数据打乱并选取训练机与测试机集
【效能優化】納尼?記憶體又溢位了?!是時候總結一波了!!
Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection
使用NLP和ML来提取和构造Web数据
[译] 5个Vuex插件,给你的下个VueJS项目
Polkadot series (2) -- detailed explanation of mixed consensus
python 保存list数据
制造和新的自动化技术是什么?
Jmeter——ForEach Controller&Loop Controller
选择站群服务器的有哪些标准呢?
TensorFlow2.0 问世,Pytorch还能否撼动老大哥地位?
Kitty中的动态线程池支持Nacos,Apollo多配置中心了
WeihanLi.Npoi 1.11.0/1.12.0 Release Notes
如何在Windows Server 2012及更高版本中將域控制器降級
利用 AWS SageMaker BlazingText 对不均衡文本进行多分类
DTU连接经常遇到的问题有哪些
“颜值经济”的野望:华熙生物净利率六连降,收购案遭上交所问询