string in .net 2005
i just switched to .net 2005 and i am getting depracted warnings. i know that the functions are different and i switched them in my program to be more secure via sprintf_s and strcpy_s. but, the string.h is having the warinings not my program.
is there a different string class for .net 2005 that has the secure functions not the depracted functions?
instead of
#include <string>
using namespace std;
i know i am asking alot of questions lately but thats good, not bad.
asking questions gains knowledge.
Just suppress that particular warning from the command line (or project options). If you know how to use those functions, they are no less secure than any other functions. You may want to take a look at each instance of the warning to make sure you're passing it good data, but then you can just suppress it.
You shouldn't be using those functions at all in C++ (or at least very rarely). You mentioned std::string (or at least you seem to know about it given that you mentioned #include <string>). Use std::string, and use its member functions. strcpy and friends are part of the C library (as opposed to the C++ library), and you shouldn't need to use them if you're using std::string.
sprintf is again part of the C library, and you should be using C++'s iostreams. If you need to format some text into a std::string instead of outputting it to a file or to the console, use std::stringstream (in the <sstream> header)
As for strcpy and co being deprecated - they're not. It's a Microsoft-only thing, as MS attempts to push people towards good C++ programming practices (and also towards .NET, I guess).
John B
sprintf is again part of the C library, and you should be using C++'s iostreams. If you need to format some text into a std::string instead of outputting it to a file or to the console, use std::stringstream (in the <sstream> header)
As for strcpy and co being deprecated - they're not. It's a Microsoft-only thing, as MS attempts to push people towards good C++ programming practices (and also towards .NET, I guess).
John B
Quote:Original post by JohnBSmall
It's a Microsoft-only thing, as MS attempts to push people towards good C++ programming practices.
Well people blame them for security issues so you can hardly blame them for trying to get people to be more secure.
Quote:Original post by JohnBSmall
You shouldn't be using those functions at all in C++ (or at least very rarely).
Note that std::copy will also cause the same warning, at least when used on PoD types where it degrades to memmove (and possibly also on more complex types, I honestly haven't checked).
Quote:Original post by 31337noob
ok so how do i get rid of all the warnings?
where is the option to do that?
i found it.
now i dont get the depracated messages
Quote:Original post by PromitQuote:Original post by JohnBSmall
You shouldn't be using those functions at all in C++ (or at least very rarely).
Note that std::copy will also cause the same warning, at least when used on PoD types where it degrades to memmove (and possibly also on more complex types, I honestly haven't checked).
Oh? I didn't realise that. The basic point still stands though.
John B
Quote:Original post by ErzengeldeslichtesQuote:Original post by JohnBSmall
It's a Microsoft-only thing, as MS attempts to push people towards good C++ programming practices.
Well people blame them for security issues so you can hardly blame them for trying to get people to be more secure.
I'm not blaming them - just trying to inform people who might not realise otherwise.
John B
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement