如何进行2个 string类型的字符串的比较?
比如 string str = "A";
然后判断str值是否为A.strcmp()函数参数好像是*char类型的 用string类型作参数的有什么函数?
如何用compare???

解决方案 »

  1.   

    你把代码发上来吧!
    我看得好头晕啊!!!!
    A.strcmp()???
      

  2.   

    string strA;
    string strB;
    i(!strcmp(strA.C_Str(),strB.C_Str())//strA ==strB
    {
    }
      

  3.   

    int strcmp( const char *string1, const char *string2 );Return Value:< 0 string1 less than string2 
    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