Dev-C++编译错误

发布于 2024-10-05 01:32:58 字数 723 浏览 0 评论 0原文

我想使用“Dev-C++”来编译c++代码。 所以我下载并安装它,并编写以下代码:

#include <iostream.h>

main () {
     cout << "124";
}

但是当我编译它时,它说:

包含在文件中 E:/Dev-Cpp/include/c++/3.4.2/backward/iostream.h:31, 来自 [我的文件路径]\Untitled1.cpp:1: E:/Dev-Cpp/include/c++/3.4.2/backward/backward_warning.h:32:2: 警告:#warning 该文件包括 至少一项已弃用或过时 标头。请考虑使用其中之一 节中找到的 32 个标头 C++ 标准的 17.4.1.2。示例包括替换标题 对于 C++ 包含的标头, 或者代替 已弃用的标头。到 禁用此警告使用 -Wno-已弃用。

看到错误后,我将代码更改为以下代码:

#include <iostream>

main () {
     cout << "124";
}

但它又说错误。

我在 Turbo C++ 中轻松编译第一个代码,但在 Dev-C++ 中编译......

我能做什么?

I want to use "Dev-C++" for compile c++ codes.
So I download and install it, and write this code:

#include <iostream.h>

main () {
     cout << "124";
}

but when I compiled it, it said:

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.

After I saw errors, I change my code to this code:

#include <iostream>

main () {
     cout << "124";
}

but it said again that errors.

I compile first code easily in Turbo C++, BUT in Dev-C++ ...

What can I do?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柠檬 2024-10-12 01:32:58

首先,确保写出 main 的完整定义,包括 int 返回类型。忽略返回类型是一种古老的、过时的做法,现在已经行不通了。

其次,在新式标头中(缺少 .h 扩展名的标头),标准库位于 std 命名空间下。有两种方法可以使您的程序正常运行:

1.cout添加std::限定符。

#include <iostream>

int main () {
    std::cout << "124";
}

2. 添加 using 声明以允许对 std 命名空间进行非限定引用。

#include <iostream>

using namespace std;

int main () {
    cout << "124";
}

First, make sure you write out the full definition of main, including the int return type. Leaving out the return type is an old, antiquated practice which doesn't fly these days.

Second, in the new-style headers—the ones missing the .h extension—the standard library is under the std namespace. There are two ways to make your program work:

1. Add an std:: qualifier to cout.

#include <iostream>

int main () {
    std::cout << "124";
}

2. Add a using declaration to allow unqualified references to the std namespace.

#include <iostream>

using namespace std;

int main () {
    cout << "124";
}
野稚 2024-10-12 01:32:58

确保将 int 放在 main () { 前面

我相信 POSIX 需要任何 C/C++ 程序的 main() 函数适当的语言标准返回一个int(如果我错了,有人纠正我)。

编辑:此外,请务必在 int main () 上方包含 using namespace std;

Make sure you put int in front of main () {

I believe any C/C++ program's main() function is required by POSIX and the appropriate language standards to return an int (someone correct me if I'm wrong).

EDIT: Also, be sure to include using namespace std; above int main ().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文