Write C++ programs under linux

The following is the code for writing a C++ program under the Linux system. I wrote it myself. I hope to point out the mistakes:

cd /

ls

mkdir workspace Create workspace directory

cd /workspace to enter this directory and write the program in this directory

ls to see if the directory was created successfully

touch test.h

ls to see if test.h was created successfully

vim test.h enters the test.h file

#Here is the note: start writing C++ code

#include <isotream>

using namespace std;

class Solution

{

    private:

        int num;//global variable

    public:

        Solution(void);

        ~Solution(void);

        void print();//function

};

:wq save and exit

touch test.cpp

vim test.cpp enters the test.cpp file

#include "test.h" refers to the header file we just customized

Solution::Solution(void)

{}

Solution::~Solution(void)

{}

void Solution::print()

{

    num=10;

    cout<<"The num is"<<num<<endl;

}

:wq

touch main.cpp

vim main.cpp

intmain()

{

    Solution s; 

    s.print();

    return 0;

}

:wq

// compile the program

gcc main.cpp -o the name of the file you want to generate (a.out is generated by default, here we set it to main.out)

//The compilation is passed, you can run the program

./main.out

//end!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324890889&siteId=291194637