Linux中gcc和g++

來源:互聯網
上載者:User

標籤:style   blog   http   color   io   os   ar   for   檔案   

    今天在Linux上編寫一個小的C++程式運行,需要用到iostream中cout,一開始建立一個hello.c的檔案編寫如下代碼:

 1 #include<stdio.h> 2 #include<sys/types.h> 3 #include<unistd.h> 4 #include<iostream> 5 using namespace std; 6 int main() 7 { 8    int i; 9    for(i=0;i<3;i++)10    {11       fork();12       //printf("H");13       cout << "H";14    }15    return 0;16 }
View Code

   通過gcc編譯該代碼會出現錯誤,沒法通過。然後我聯想到在windows下的c++源檔案都是.cpp類型的,我想是不是自己檔案尾碼有問題,因此改為hello.cpp,然後再次編譯,還是沒法通過(我是用gcc編譯)。。。幾次折騰後,我突然想起Linux下還有一個g++的編譯工具,我就用g++試了一次。。嘿嘿,這次沒問題了。。

   從這個小小的執行個體知道,Linux下C和C++還是需要很好去別的。。。

Linux中gcc和g++

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.