boost format problem

Started by
3 comments, last by Decept 15 years, 8 months ago
I'm new to std::string and boost::format and such. Im trying to do the following:

int value = 5;
format fmter( "Testing stuff %1%" );
fmter % value;

the second line gives a very long warning, here is part of it: warning C4996: 'std::char_traits<char>::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct. Am I doing something wrong? I've searched around and this seems to be the way to do it.
Advertisement
Quote:Original post by Decept
I'm new to std::string and boost::format and such. Im trying to do the following:

*** Source Snippet Removed ***

the second line gives a very long warning, here is part of it:

warning C4996: 'std::char_traits<char>::copy': Function call with parameters that may be unsafe - this call relies on the caller to check that the passed values are correct.

Am I doing something wrong? I've searched around and this seems to be the way to do it.


That warning is for 'depracated functions' as determined by microsoft. In an effort to curb common bugs when dealing with C-style strings Microsoft's visual C++ team has made 'safe' versions of many standard library functions, one of which is std::char_traits<T>::copy. Boost uses this member function in its headers so Visual C++ flags it as a warning.

You can either ignore the warning every time you compile, use a compiler directive to ignore the warning (see the example programs. The #pragma is commented out, just uncomment it to use), modify boost to use the safe versions, or drop boost entirely.

Maybe in future versions of boost they will fix the warning for MS compilers.

C++: A Dialog | C++0x Features: Part1 (lambdas, auto, static_assert) , Part 2 (rvalue references) , Part 3 (decltype) | Write Games | Fix Your Timestep!

Your code should be correct. It's Microsoft again going and deprecating stuff that is perfectly standard and OK to use.

You should probably trust that your boost implementation is correct and Google for a way to turn warnings of this kind off (or just ignore "deprecated"-warnings).
Defining _SCL_SECURE_NO_DEPRECATE (_SCL_SECURE_NO_WARNINGS in VC9) and _CRT_SECURE_NO_DEPRECATE in your project settings, or somewhere sufficiently early in the code, should also do the trick.
Thank you guys, much appreciated

This topic is closed to new replies.

Advertisement