Sign in to follow this  
31337noob

string in .net 2005

Recommended Posts

31337noob    101
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.

Share this post


Link to post
Share on other sites
hplus0603    11356
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.

Share this post


Link to post
Share on other sites
JohnBSmall    881
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
Promit    13246
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).

Share this post


Link to post
Share on other sites
31337noob    101
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

Share this post


Link to post
Share on other sites
JohnBSmall    881
Quote:
Original post by Promit
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).

Oh? I didn't realise that. The basic point still stands though.

John B

Share this post


Link to post
Share on other sites
JohnBSmall    881
Quote:
Original post by Erzengeldeslichtes
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.

I'm not blaming them - just trying to inform people who might not realise otherwise.

John B

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this