[问题] Mac上include iostream就不需要time.h?

楼主: ip3311 (泡泡)   2014-04-29 15:56:53
开发平台(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 也有同样问题
作者: shadow0326 (非议)   2014-04-29 17:13:00
用到什么就inc什么就对了 标准库实作互相参考很常见
楼主: ip3311 (泡泡)   2014-04-29 17:32:00
感谢s大 看来是实作的差异

Links booklink

Contact Us: admin [ a t ] ucptt.com