我想使用“Dev-C++”来编译 C++ 代码。 所以我下载并安装了它,并编写了这段代码:
#include <iostream.h>
main () {
cout << "124";
}
但是当我编译它时,它说:
In file included from E:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, from [myfile path]\Untitled1.cpp:1: E:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: warning: #warning This file includes at least one deprecated or antiquated header. Please consider using one of the 32 headers found in section 17.4.1.2 of the C++ standard. Examples include substituting the header for the header for C++ includes, or instead of the deprecated header . To disable this warning use -Wno-deprecated.
看到错误后,我将代码更改为以下代码:
#include <iostream>
main () {
cout << "124";
}
但它又说错误。
我在 Turbo C++ 中很容易编译第一段代码,但在 Dev-C++ 中...
我能做什么?
最佳答案
首先,确保写出 main
的完整定义,包括 int
返回类型。省略返回类型是一种古老的、过时的做法,现在已经行不通了。
其次,在新式 header 中——缺少 .h
扩展名的 header ——标准库位于 std
命名空间下。有两种方法可以使您的程序运行:
1. 添加一个 std::
限定符到 cout
。
#include <iostream>
int main () {
std::cout << "124";
}
2. 添加 using
声明以允许对 std
命名空间的非限定引用。
#include <iostream>
using namespace std;
int main () {
cout << "124";
}
关于c++ - Dev-C++ 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4298981/