John E
February 7th, 2008, 02:13 AM
Firstly, is std::string the same thing as basic_string? The reason I'm asking is that I can never find anything on MSDN about std::string - but basic_string seems very similar.
Anyway, here's my question - Yesterday I was looking at some code that I wrote a long time ago. It does some string comparisons and I realised that I should probably have written something like this:-
#include <string>
using namespace std;
void MyFunc ( string someString, char* compareString )
{
if ( 0 == someString.compare( string( compareString )))
; do something here....
}whereas in fact, I did it this way:-
#include <string>
using namespace std;
void MyFunc ( string someString, char* compareString )
{
if ( someString == compareString )
; do something here....
}That code appears to work just fine - even though this MSDN article (http://msdn2.microsoft.com/en-us/library/5zz6weyz(VS.80).aspx) seems to suggest that basic_string has no equality operators.
Am I looking at the wrong MSDN article? Or is it out of date? Or have I somehow been kidding myself all these years and the code doesn't really work?? :confused:
Anyway, here's my question - Yesterday I was looking at some code that I wrote a long time ago. It does some string comparisons and I realised that I should probably have written something like this:-
#include <string>
using namespace std;
void MyFunc ( string someString, char* compareString )
{
if ( 0 == someString.compare( string( compareString )))
; do something here....
}whereas in fact, I did it this way:-
#include <string>
using namespace std;
void MyFunc ( string someString, char* compareString )
{
if ( someString == compareString )
; do something here....
}That code appears to work just fine - even though this MSDN article (http://msdn2.microsoft.com/en-us/library/5zz6weyz(VS.80).aspx) seems to suggest that basic_string has no equality operators.
Am I looking at the wrong MSDN article? Or is it out of date? Or have I somehow been kidding myself all these years and the code doesn't really work?? :confused: