Warning with boost :: split when compiling

Possible duplicate:
Why does boost: split () call 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 did I do wrong? What can I do to prevent these error messages?

+7
source share
2 answers

You have done nothing wrong. Visual Studio is overly cautious. In debug mode, the visual studio uses something called Proven Iterators. Pointers are also iterators, but the validation mechanism does not work with them. Therefore, when the standard library algorithm is called with pointers, something that boost::split does, it generates this warning.

You will get the same warning with this explicitly safe code:

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

Disable the warning. This is for beginners. This is the default for beginner security, because if it is disabled by default, they don’t know how to enable it.

+11
source

You didn’t do anything wrong, and if you look at the warning, it doesn’t seem scary :) I also think that in this case you do not need to perform any actions on this.

+1
source

All Articles