(MSVC 2017 / WALL& / WX)包括Iostream会产生800条警告 [英] (MSVC 2017 /WALL & /WX) Including Iostream Produces 800 Warnings

查看:112
本文介绍了(MSVC 2017 / WALL& / WX)包括Iostream会产生800条警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在下个季度审查优化的C ++课程的材料。本课程的教授正在为我们的项目属性强制执行/ WALL和/ WX。我遇到的问题是,包含Iostream库会产生800多个警告。这是我尝试运行的代码:

Reviewing material for an optimized C++ course next quarter. The professor for this course is enforcing /WALL and /WX for our project properties. The problem I'm having is that including the Iostream library produces over 800 warnings. Here's the code I'm attempting to run:

#include "pch.h"
#include <iostream>

int main() {
  std::cout << "Hello World";
  return(0);
}

我收到的一些警告包括:

A few of the warnings that I'm receiving includes:

C4514 'abs': unreferenced inline function has been removed
C4774 'sprintf_s': format string in argument 3 is not a string literal
C4820 'std::basic_ios ...': '7' bytes of padding added after...

之前,我已通过电子邮件向教授发送了'7'个填充字节询问警告并被告知:

Before asking Stack I emailed the Prof to ask about the warnings and was told:


您应该包括iostream

You should be including iostream

如果收到100条警告,则包括不需要的标头

If you get 100 warnings you included a header that's not needed

是否缺少某些内容?我知道我将无法编辑iostream的源文件,因为它不是可移植的编码。我环顾四周,看看是否可以明确包含cout,cin等函数。但是,我觉得这不是正确的解决方案。

Is there something I'm missing? I know I wouldn't be able to edit source files for iostream as that's not portable coding. I looked around to see if I could explicitly include functions such as cout, cin, etc. Yet, I don't feel like this is the correct solution.

编辑:

用户要求提供一个更明确的警告消息的示例,以防其中缺少某些内容。以下是一些示例:

A user requested an example of a more explicit warning message in case there was something missing in there. Here are a few:

C415 'abs': referenced inline function has been removed (Project: Hello World) (File: stdlib.h)
C4710 'int sprintf_s(char *const....: function not inlined. (Project: Hello World) (File: stdio.h)

教授正在通过Visual Studio使用GCC,我们的设置从存储库中提取为预制项目。

The professor is using GCC through Visual Studio and our settings are pulled from a repository as premade projects.

推荐答案

您的教授很简单,是错误的。

Your professor is, quite simply, wrong.

这与包括不需要的标题无关(为什么会生成警告?),但是使用 / WALL 时,显示了那里的stdlib实现的一些缺陷

This has nothing to do with "including a header that's not needed" (why would that generate warnings?), but with using /WALL, which reveals some flaws in the stdlib implementation there!

不建议使用此开关;引用 James McNellis 在上面提到的问题下迅速启用

This switch is not recommended; quoting James McNellis who gets it bang-on under the above referenced question:


/ Wall 会启用许多警告,尽管有时可能有用,但在大多数情况下没有用。在Visual C ++中, / Wall 与g ++上的 -Wall 并不相同(实际上,g ++具有 / Wall 错误,,因为它实际上并未启用所有警告)。无论如何,在Visual C ++中,所有常见且重要的有用警告均由 / W4 启用。

/Wall enables many warnings that, while potentially useful sometimes, are not useful most of the time. /Wall in Visual C++ does not mean the same thing as -Wall on g++ (really, g++ "has /Wall wrong," since it doesn't actually enable all warnings). In any case, in Visual C++, all of the commonly important and useful warnings are enabled by /W4.

我将在Visual Studio中使用 / W4 (在GCC中使用 -Wall -Wextra )。

I would use /W4 in Visual Studio (and -Wall -Wextra in GCC).

很明显,除了建议您说些的话,我不能帮您说服您的教授。并发现这是由于 / Wall 过于严格,并在Visual Studio自己的标头上生成警告。他们建议我们使用 / W4 ……您怎么看?

Obviously I can't help you to persuade your professor of this, other than to suggest saying something along the lines of "I asked on Stack Overflow and found out that this is due to /Wall being too strict and generating warnings on Visual Studio's own headers. They suggest we use /W4 instead. . What do you think?"

确实需要 #include< iostream> ; ,的确,您绝对不要修改提供的标准标题。另外,别忘了流’\n’结束输出行!

It is true that you need to #include <iostream>, and it is true that you should never modify the provided standard headers. Also, don't forget to stream a '\n' to end your output line!

这篇关于(MSVC 2017 / WALL&amp; / WX)包括Iostream会产生800条警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆