不需要的VS2015编译器标头警告信息

时间:2015-12-01 04:08:15

标签: c++ visual-studio header-files

我编写了一个自治应用程序,它编译学生发送给我的C和C ++代码并将结果发送给他们。由于这些都是初学者,我不想用他们甚至不理解的大量信息来压倒他们。我正在使用的编译器之一是命令行中的VS2015编译器,其中包含以下选项:

/MT /GS /O2 /W4 /nologo /EHsc /analyze- /errorReport:none /wd4001 /wd4210 /wd4701 /wd4706 /wd4996 /wd4554 /wd4512 /wd4716

我收到的.cpp文件中的一个不正确编写的代码语句如下所示,其中operand2的类型为ifstream。我希望并确实得到编译器错误:

cerr << "Couldn't open file: " << operand2 << '\n';

但是,我得到的远远超过我想要的,如下:

C2A8E1_OpenFiles.cpp(47): error C2678: binary '<<': no operator found which takes a left-hand operand of type 'std::basic_ostream<char,std::char_traits<char>>' (or there is no acceptable conversion)
Microsoft Visual Studio 14.0\VC\INCLUDE\ostream(497): note: could be 'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(std::basic_streambuf<char,std::char_traits<char>> *)'
Microsoft Visual Studio 14.0\VC\INCLUDE\ostream(477): note: or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(const void *)'
Microsoft Visual Studio 14.0\VC\INCLUDE\ostream(457): note: or       'std::basic_ostream<char,std::char_traits<char>> &std::basic_ostream<char,std::char_traits<char>>::operator <<(long double)'
...and on and on and on...

它不仅告诉我我的档案有什么问题,而且还在评论我此刻并不关心的事情,这只会让我的学生感到困惑。使用英特尔编译器,我只得到以下内容,这对于本课程来说已经足够了,而且就是我想要的:

C2A8E1_OpenFiles.cpp(47): error: no operator "<<" matches these operands
   operand types are: std::basic_ostream<char, std::char_traits<char>> << std::ifstream
   cerr << "Couldn't open file: " << arrayPtr[ifstreamIndex] << '\n';

英特尔编译器选项设置如下,它们指定的警告级别甚至高于Microsoft编译器:

/MT /GS /O2 /W5 /Za /nologo /EHsc /analyze- /errorReport:none /J /Wcheck /Wport /Qeffc++ /Qdiag-error-limit:10 /Qlong-double /Qms0 /wd4001 /wd4210 /wd4701 /wd4706 /wd4996 /wd4554 /wd4512 /wd4716 /wd1418 /wd2015 /wd2013 /wd1786 /wd1419 /wd981 /wd991 /wd2012 /wd1572 /wd9 /wd187

我为Visual Studio选择W4警告级别只是为了获得最彻底的检查,但即使我将其降低到W2,我仍然会得到所有不必要的混乱。有没有解决这个问题的方法?使用编译指示或以其他方式修改现有代码是不切实际的,因为我编译的所有文件都是在我得到之前预先编写的。

谢谢, 射线

0 个答案:

没有答案
相关问题