当我只使用
gcc code.c
没有任何消息,并且成功生成了一个输出文件。输出的文件有效。但是,当我在 IDE 中尝试使用相同的 cygwin 安装的 gcc 编译器时(我尝试过 Netbeans 和 Dev-C++),我收到以下错误
main.cpp:27: error: `exit' undeclared (first use this function)
main.cpp:27: error: (Each undeclared identifier is reported only once for each function it appears in.)
main.cpp:77: error: `write' undeclared (first use this function)
main.cpp:78: error: `close' undeclared (first use this function)
我看不出有什么不同。为什么它不编译?
好的,问题是在 IDE 中,该文件具有 .cpp 扩展名,而当我从终端编译时,它具有 .c 扩展名。所以,我的新问题是为什么当它被视为 c++ 文件时它不编译。C 不是 C++ 的子集吗?