当前位置:网站首页>[C / C + + 2] clion configuration and running C language

[C / C + + 2] clion configuration and running C language

2020-11-06 01:22:08 Elementary school students in IT field

【C/C++ 1】Clion Configuration and operation C Language
【C/C++ 2】Clion Configuration and operation C Language

One 、C++ Call a function in an external file (clion)

Method 1 、  Build a new project in the current project , Add the following files to the project
      The main function map1.cpp, Add  #include “map7.h”,

Method 2 :  In the main function map1.cpp Add directly to  #include “add.cpp”,#include " sub.cpp", Put these three files in the same directory . Reference link : Method 2

I will give an example of method one :
1.
 Insert picture description here
The header file map7.h Statement map7.ccp Middle function int test_map7();

#ifndef MAP_MAP7_H
#define MAP_MAP7_H



int test_map7();

#endif //MAP_MAP7_H

map7.ccp file


```cpp

#include "map7.h"
#include <iostream>

using namespace std;

int test_map7(){
    
    int var1;
    char var2[10];
    cout << "var1 The address of the variable " << &var1 <<endl;
    cout << "var2 The address of the variable " << &var2 <<endl;

    int var =20;// Declaration of actual variables 
    int *ip; // Declaration of pointer variables 

    ip=&var; // Store... In pointer variables var The address of 
    

    cout<< "value of var variable"<<var <<endl;
    // Output address stored in pointer variable 
    cout << "var The address of the variable " << &var <<endl;
    cout<< "address stored in ip variable:"<< ip<<endl;
    //  Access the address in the pointer de value 
    cout <<"value of *ip variable:" << *ip <<endl;
}

stay map1.cpp I quote


#include<iostream>
#include "map7.h"

using namespace std;

int main() {
    
    cout << "type: \t\t" << "************size**************" << endl;
   
    test_map7();
    return 0;
}

stay clion Pay attention to modify CMakeLists.txt,
add_executable(map map1.cpp) Add a reference function in the 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++ Program

vim To write C、C++ The procedure ( With hello world For example ):
1、vim hello.c/hello.cpp.
establish hello.c/hello.cpp file , And enter vim Interface ;
2、 type i, Enter input mode .
3、 To write hello.c/hello.cpp Program .
4、 According to the first Esc key , Exit input mode ,:wq ( Press Shift+: key , Enter command mode . Input wq), Save and exit .
 Insert picture description here
5、 compile hello.c/hello.cpp.
5.1、 about C Program : use gcc hello.c You can compile ;
5.2、 about C++ Program : use g++ hello.cpp Compiling . After compiling , Both generate a.out The executable of ;
 Insert picture description here
6、 Type instruction "./a.out", Run the program .
 Insert picture description here
7、 stay Terminal Displayed on the "hello world" The successful .

版权声明
本文为[Elementary school students in IT field]所创,转载请带上原文链接,感谢