简体   繁体   English

c++ 简单程序错误

[英]c++ simple program error

I have created a file called untitled1.cpp in dev-cpp with the following script:我使用以下脚本在 dev-cpp 中创建了一个名为untitled1.cpp的文件:

#include <iostream.h>
using namespace std;
int main(){
    cout << "C++";
    return 0;
}

But the compiler shows errors like:但是编译器显示如下错误:

1 F:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31, 1 F:\Dev-Cpp\include\c++\3.4.2\backward\iostream.h:31,
from F:\Dev-Cpp\Untitled1.cpp In file included from include/c++/3.4.2/backward/iostream.h:31, from F:\Dev-Cpp\Untitled1.cpp 32:2 F:\Dev-Cpp\include\c++\3.4.2\backward\backward_warning.h #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.来自 F:\Dev-Cpp\Untitled1.cpp 在 include/c++/3.4.2/backward/iostream.h:31 包含的文件中,来自 F:\Dev-Cpp\Untitled1.cpp 32:2 F:\Dev- Cpp\include\c++\3.4.2\backward\backward_warning.h #warning 此文件至少包含一个已弃用或过时的 header。请考虑使用 C++ 标准第 17.4.1.2 节中的 32 个标头之一。 Examples include substituting the header for the header for C++ includes, or instead of the deprecated header. To disable this warning use -Wno-deprecated.示例包括将 header 替换为 header 替换为 C++ 包含,或者代替弃用的 header。要禁用此警告,请使用 -Wno-deprecated。

What is the error that I have?我有什么错误? How do I fix it?我如何解决它?

In C++ you import the standard library without using the .h suffix.在 C++ 中,您导入标准库时未使用.h后缀。

#include <iostream>

So your fixed example:所以你的固定例子:

#include <iostream>

int main(int argc, char **argv) {
    std::cout << "C++";
    return 0;
}

Your code is not standard C++. You should say #include <iostream> (no ".h".), Whatever source you have been learning this from is about 25 years out of date.您的代码不是标准的 C++。您应该说#include <iostream> (没有“.h”。),无论您从何处学习此代码,都已过时约 25 年。 and you should consider getting some more modern material.你应该考虑得到一些更现代的材料。

(The "iostreams.h" header was part of a very early non-standard library in the early 1990s, and so it's being kept around for "compatibility" reasons, or to catch very inert programmers and give them a helpful hint.) (“iostreams.h”header 是 1990 年代早期一个非常早期的非标准库的一部分,因此出于“兼容性”的原因,或者为了抓住非常惰性的程序员并给他们一个有用的提示,它被保留下来。)

Use header file as #include<iostream> instead of #include<iostream.h>使用 header 文件作为#include<iostream>而不是#include<iostream.h>

Include iostream instead of iostream.h包括iostream而不是iostream.h

It says that the header, in this case, iostream.h is deprecated or antiquated.它说 header,在这种情况下, iostream.h已弃用或过时。 (You only have one header, so that's the one! Just read the error message!) (您只有一个 header,所以就是这个!请阅读错误消息!)

So you'll have to use iostream , not iostream.h .所以你必须使用iostream ,而不是iostream.h

This is just a warning.这只是一个警告。

I think that you could try to include iostream instead of iostream.h in order to fix it.我认为您可以尝试包含iostream而不是iostream.h来修复它。

You've posted the reason in your question already!您已经在问题中发布了原因!

This file includes at least one deprecated or antiquated header.此文件至少包含一个已弃用或过时的 header。

The real question should therefore be: "Which one is antiquated, how do I replace it?", not "What's the error".因此,真正的问题应该是:“哪个过时了,我该如何替换它?”,而不是“有什么错误”。 Answer: Use <iostream> .答案:使用<iostream> The <*.h> versions are pre-standard, legacy headers. <*.h>版本是准标准的旧标头。

So: Read error messages, people.所以:阅读错误信息,各位。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM