当前位置:网站首页>【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
边栏推荐
- 基于深度学习的推荐系统
- Polkadot series (2) -- detailed explanation of mixed consensus
- 条码生成软件如何隐藏部分条码文字
- 前端模組化簡單總結
- C++和C++程序员快要被市场淘汰了
- 50 + open source projects are officially assembled, and millions of developers are voting
- 10 easy to use automated testing tools
- 6.9.1 flashmapmanager initialization (flashmapmanager redirection Management) - SSM in depth analysis and project practice
- 【QT】 QThread部分原始碼淺析
- drf JWT認證模組與自定製
猜你喜欢

基于深度学习的推荐系统

Aprelu: cross border application, adaptive relu | IEEE tie 2020 for machine fault detection

通过深层神经网络生成音乐

中国提出的AI方法影响越来越大,天大等从大量文献中挖掘AI发展规律

做外包真的很难,身为外包的我也无奈叹息。

2018个人年度工作总结与2019工作计划(互联网)

免费的专利下载教程(知网、espacenet强强联合)

Examples of unconventional aggregation

DRF JWT authentication module and self customization

你的财务报告该换个高级的套路了——财务分析驾驶舱
随机推荐
xmppmini 專案詳解:一步一步從原理跟我學實用 xmpp 技術開發 4.字串解碼祕笈與訊息包
(2)ASP.NET Core3.1 Ocelot路由
Flink的DataSource三部曲之二:内置connector
python 保存list数据
Dapr實現分散式有狀態服務的細節
Anomaly detection method based on SVM
Top 10 best big data analysis tools in 2020
Pycharm快捷键 自定义功能形式
Jmeter——ForEach Controller&Loop Controller
6.7 theme resolver theme style parser (in-depth analysis of SSM and project practice)
自然语言处理之命名实体识别-tanfordcorenlp-NER(一)
【快速因數分解】Pollard's Rho 演算法
vite + ts 快速搭建 vue3 專案 以及介紹相關特性
DTU连接经常遇到的问题有哪些
C language 100 question set 004 - statistics of the number of people of all ages
The practice of the architecture of Internet public opinion system
Ubuntu18.04上安裝NS-3
【QT】 QThread部分原始碼淺析
不吹不黑,跨平臺框架AspNetCore開發實踐雜談
Details of dapr implementing distributed stateful service