Results 1 to 5 of 5

Thread: In which way I can use the compare() in CPP programs

  1. #1
    Join Date
    Jan 2010
    Posts
    26

    In which way I can use the compare() in CPP programs

    Hey, How are you all!! I am making one project in the C++ language using the Microsoft Access as the Backend. I can know the string functions of the C++ language. I can also used the string functions in my project. So, I just want to know about the compare() function of the C++ language. I also would like to know In which way I can use the compare function in the C++ program of lines. If there can be anyone who can have the knowledge then reply me.

  2. #2
    Join Date
    Oct 2005
    Posts
    2,393

    Re: In which way I can use the compare() in CPP programs

    Hello, The compare() function can be used in the C++ language to compare the two strings that can be specified by the user of the program. The following can be the general syntax of the compare() function in the C++ language as :
    Code:
    int compare ( const string& str ) const;
    int compare ( const char* t ) const;
    int compare ( szt ps, szt m1, const string& str ) const;

  3. #3
    Join Date
    May 2008
    Posts
    2,389

    Re: In which way I can use the compare() in CPP programs

    The following program could illustrates you about that how you could use the compare() function in the C++ language programming while using the compare() function in the programming as shown below :
    Code:
    #include <iostream>
    #include <string>
    using namespace std;
    int main ()
    {
      string a ("green apple");
      string b ("red apple");
      if (a.compare(b) != 0)
        cout << a << " is not " << b << "\n";
      if (a.compare(6,5,"apple") == 0)
        cout << "still, " << a << " is an apple\n";
      if (b.compare(b.size()-5,5,"apple") == 0)
        cout << "and " << b << " is also an apple\n";
      if (a.compare(6,5,b,4,5) == 0)
        cout << "therefore, both are apples\n";
      return 0;
    }
    Output:
    Code:
    green apple is not red apple
    still, green apple is an apple
    and red apple is also an apple
    therefore, both are apples

  4. #4
    Join Date
    Feb 2008
    Posts
    1,852

    Re: In which way I can use the compare() in CPP programs

    The following can be the parameters of the find_end() function in the C++ language :
    1. s : This parameter of the C++ language can contains an array with a given specified sequence of the characters that can be used as comparing string.
    2. pos1 : This parameter of the C++ language can contains the position of the starting of the sub-string that can be compared.
    3. null-character :This parameter of the C++ language can contains the length that can not be determined by any occurrence of the null-characters but by parameter n2, In the last version of the member.
    4. str : This parameter of the C++ language can contains the string object with the content that can be used as comparing string.

  5. #5
    Join Date
    Jan 2008
    Posts
    1,521

    Re: In which way I can use the compare() in CPP programs

    PROGRAM :
    Code:
    #include <string.h>
    #include <stdio.h>
    #include <conio.h>
    #include <dos.h>
    int main( void )
    {
       char bfr[61] = "How long am I?";
       int ln;
       ln = strlen( bfr );
       printf( "'%s' is %d characters long\n", bfr, ln );
    }
    Output :
    Code:
    'How long am I?' is 14 characters long

Similar Threads

  1. Replies: 7
    Last Post: 14-08-2009, 09:03 PM
  2. Replies: 0
    Last Post: 10-01-2009, 08:37 PM
  3. Replies: 3
    Last Post: 15-11-2008, 07:27 PM
  4. Replies: 2
    Last Post: 24-09-2007, 06:19 AM
  5. Replies: 3
    Last Post: 05-09-2006, 05:34 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,558,091.17746 seconds with 17 queries