Error

C++博客 首页 新随笔 联系 聚合 管理
  217 Posts :: 61 Stories :: 32 Comments :: 0 Trackbacks
搞了搞split,发现boost里边已经有了,就拿过来直接用,之前翻了下facebook的,也没见比boost更容易读,还是boost算了。
在vs2012上编译了一下,发现有问题:error C4996: 'std::_Copy_impl': Function call with para

找了下,老外是这么说的:http://stackoverflow.com/questions/14141476/warning-with-boostsplit-when-compiling

You haven't done anything wrong. Visual Studio is being overly cautious. In debug mode, visual studio uses something called "Checked Iterators". Pointers are also iterators, but the checking mechanism doesn't work with them. So when a standard library algorithm is called with pointers, which is something that boost::split does, it issues this warning.

You'll get the same warning with this obviously safe code:

int main()
{
    int x[10] = {};
    int y[10] = {};
    int *a = x, *b = y;
    std::copy(a, a+10, b);
}

Disable the warning. It's for beginners. It's on by default for the safety of beginners, because if it was off by default, they wouldn't know how to turn it on.





#include <boost/algorithm/string/classification.hpp>
#include <boost/algorithm/string.hpp>
void LearnSplit()
{
    std::string strTem("1,2,3,4");
    std::list<std::string> listStrTem;
    std::vector<std::string> vectorStrTem;
    boost::split(listStrTem, strTem, boost::is_any_of(","));
    boost::split(vectorStrTem, strTem, boost::is_any_of(","));
    for(auto item : listStrTem)
    {
        std::cout << item.c_str() << std::endl;
    }
    std::string s = "Hello, the beautiful world!";
    std::vector<std::string> rs;
    boost::split( rs, s, boost::is_any_of( " ,!" ), boost::token_compress_on );
}
int _tmain(int argc, _TCHAR* argv[])
{
    LearnSplit();
return 0;
}
posted on 2013-04-11 00:29 Enic 阅读(1046) 评论(0)  编辑 收藏 引用 所属分类: boost

只有注册用户登录后才能发表评论。
网站导航: 博客园   IT新闻   BlogJava   博问   Chat2DB   管理