在MSVC ++ 2010中禁用警告 [英] Disable warning in MSVC++2010

查看:465
本文介绍了在MSVC ++ 2010中禁用警告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码:

/** Stupidly copies unicode chars into normal chars. */
std::string wstring2string(__in  const std::wstring& s)
{
    std::string temp(s.length(), ' ');
#pragma warning(push)
#pragma warning(disable: 4244) // possible loss of data
    std::copy(s.begin(), s.end(), temp.begin());
#pragma warning(pop)
    return temp;
}

我的编译器仍会显示警告C4244: / p>

My compiler still shows me warning C4244:

1>c:\program files\microsoft visual studio 10.0\vc\include\xutility(2144): warning C4244: '=': Konvertierung von 'const wchar_t' in 'char', möglicher Datenverlust
1>          c:\program files\microsoft visual studio 10.0\vc\include\xutility(2165): Siehe Verweis auf die Instanziierung der gerade kompilierten Funktions-template "_OutIt std::_Copy_impl<_InIt,_OutIt>(_InIt,_InIt,_OutIt,std::_Nonscalar_ptr_iterator_tag)".

(英文:Conversion of const wchar_t char ,可能会丢失数据,请参阅刚编译的函数模板的实例化...)。

(in English: "Conversion of const wchar_t to char, possible loss of data, see reference to instantiation of the just compiled function template …").

推荐答案

为了摆脱这个警告你需要添加 #pragma warning ... 包含该函数的头文件。在你的情况下,这是xutility。其中包含多个其他文件。所以很难找到。但是你可以这样尝试。

Well to get rid of this warning you need to add the #pragma warning... around your header file that includes the function. In your case this is xutility. Which is included by multiple other files. So it will be difficult to find. But you can try it this way.

#pragma warning(push)
#pragma warning(disable: 4244) // possible loss of data
#include <xutility>
#pragma warning(pop)
Your includes go here...
std::string wstring2string(__in  const std::wstring& s)
{
    std::string temp(s.length(), ' ');
    std::copy(s.begin(), s.end(), temp.begin());
    return temp;
}

除此之外,我建议正确转换。请查看 ICU ,或至少使用标准功能。例如。 mbstowcs

Beside of this I would recommend to a correct conversion. Have a look at ICU for example or at least use the function from standard. E.g. mbstowcs

这篇关于在MSVC ++ 2010中禁用警告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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