How to run a C++/Java program?

1. C++:

用隨意的編輯軟體打好程式後
ex:

#include <iostream>
using std::cout;
using std::endl;

int main(int argc, char *argv[])
{
    if(argc!=4){
        cout<<“wrong argument number”<<endl;
    }
    else{
        cout<<“argv[1]=”<<argv[1]<<endl;
        cout<<“argv[2]=”<<argv[2]<<endl;
        cout<<“argv[3]=”<<argv[3]<<endl;
    }
    cout << “hello world!” << endl;
    return 0;
}
在terminal裡切到該目錄後先compile
>> g++ hw1.cpp
>> ./a.out

compile後會出現a.out
run時為什麼要打./
因為要告訴檔案是在目前目錄下的檔
而不是指令 例如ls 這種容易混淆的檔名
by 系統程式的熊老師

2. Java:

用隨意的編輯軟體打好程式後
ex:

public class hw1
{
    public static void main(String args[])
    {
        System.out.println(“helo world!”);
    }
}

在terminal裡切到該目錄後先compile
>> javac hw1.java
>> java hw1

compile後會出現hw1.class
但是run的時候不需要打出.class

作者

RongSon

Graduate Student of CCU COMM Game Development, Network Communication, macOS/Ubuntu/Android, Arduino/Raspberry Pi/Intel Edison, Java/Python/C/C++

發佈留言

發佈留言必須填寫的電子郵件地址不會公開。 必填欄位標示為 *