Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning with boost::split when compiling [duplicate]

Possible Duplicate:
Why does calling boost:split() give so many warnings?

So, this is my code:

Account ParseString(string data){
    vector <string> fields;
    boost::split( fields, data, boost::is_any_of( "a,;" ));
    int limit = fields.size();
    for(int i = 0; i < limit; i++)
        cout << fields[i] << endl;
}

and this is what I get when trying to compile:

d:\program files (x86)\visualstudio\vc\include\xutility(2227): warning C4996: 'std::_Copy_impl': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. To disable this warning, use -D_SCL_SECURE_NO_WARNINGS. See documentation on how to use Visual C++ 'Checked Iterators'

My question is, what have I done wrong? What can I do to prevent those error messages?

like image 375
Theolodis Avatar asked Jan 03 '13 15:01

Theolodis


2 Answers

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.

like image 87
Benjamin Lindley Avatar answered Sep 28 '22 04:09

Benjamin Lindley


You have done nothing wrong and if you have a look at the warning it does not seem that scary :) Also I believe in this case you are not required to perform any action on that one.

like image 42
Ivaylo Strandjev Avatar answered Sep 28 '22 03:09

Ivaylo Strandjev