[問題] Mac上include iostream就不需要time.h?

看板C_and_CPP作者 (泡泡)時間11年前 (2014/04/29 15:56), 11年前編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/3 (看更多)
開發平台(Platform): (Ex: VC++, GCC, Linux, ...) Mac OS 額外使用到的函數庫(Library Used): (Ex: OpenGL, ...) iostream time.h 問題(Question): 寫 C++ 突然發現的 測試程式碼"untitled.cpp": ================= #include <iostream> using namespace std; int main(){ clock_t TIME = clock(); printf("%f\n", (clock() - TIME)/ (double)(CLOCKS_PER_SEC)); return 0; } ================= 編譯 g++ untitled.cpp -o untitled.out 完全沒警告和錯誤 難道include iostream 會自動 include time.h? 另外 我再測試 ========== #include <stdio.h> int main(){ clock_t TIME = clock(); printf("%f\n", (clock() - TIME)/ (double)(CLOCKS_PER_SEC)); return 0; } =========== gcc untitled.cpp -o untitled.out 就會有錯誤訊息了 我不知道該怎麼去檢查 compiler 運作的方式,google 也沒找到什麼相關的 Mac 上是裝 Xcode 就可以用 gcc 我認為是 Xcode 的 bug 導致 其他 IDE 都拿 Xcode 裝的 gcc 來編譯 所以都一樣的結果 預期的正確結果(Expected Output): 產生錯誤訊息 錯誤結果(Wrong Output): 完全正確 程式碼(Code):(請善用置底文網頁, 記得排版) 補充說明(Supplement): Xcode 有同樣問題 Code::block 也有同樣問題 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 111.250.190.128 ※ 文章網址: http://www.ptt.cc/bbs/C_and_CPP/M.1398758216.A.307.html ※ 編輯: ip3311 (111.250.190.128), 04/29/2014 15:59:49

04/29 17:13, , 1F
用到什麼就inc什麼就對了 標準庫實作互相參考很常見
04/29 17:13, 1F

04/29 17:32, , 2F
感謝s大 看來是實作的差異
04/29 17:32, 2F
文章代碼(AID): #1JNrj8C7 (C_and_CPP)
文章代碼(AID): #1JNrj8C7 (C_and_CPP)