如何进行2个 string类型的字符串的比较?
比如 string str = "A";
然后判断str值是否为A.strcmp()函数参数好像是*char类型的 用string类型作参数的有什么函数?
如何用compare???
比如 string str = "A";
然后判断str值是否为A.strcmp()函数参数好像是*char类型的 用string类型作参数的有什么函数?
如何用compare???
我看得好头晕啊!!!!
A.strcmp()???
string strB;
i(!strcmp(strA.C_Str(),strB.C_Str())//strA ==strB
{
}
0 string1 identical to string2
> 0 string1 greater than string2 Example/* STRCMP.C */#include <string.h>
#include <stdio.h>char string1[] = "The quick brown dog jumps over the lazy fox";
char string2[] = "The QUICK brown dog jumps over the lazy fox";void main( void )
{
char tmp[20];
int result;
/* Case sensitive */
printf( "Compare strings:\n\t%s\n\t%s\n\n", string1, string2 );
result = strcmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\tstrcmp: String 1 is %s string 2\n", tmp );
/* Case insensitive (could use equivalent _stricmp) */
result = _stricmp( string1, string2 );
if( result > 0 )
strcpy( tmp, "greater than" );
else if( result < 0 )
strcpy( tmp, "less than" );
else
strcpy( tmp, "equal to" );
printf( "\t_stricmp: String 1 is %s string 2\n", tmp );
}
OutputCompare strings:
The quick brown dog jumps over the lazy fox
The QUICK brown dog jumps over the lazy fox strcmp: String 1 is greater than string 2
_stricmp: String 1 is equal to string 2