Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 26-02-2010
Member
 
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.
Reply With Quote
  #2  
Old 26-02-2010
Member
 
Join Date: Oct 2005
Posts: 2,389
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;
Reply With Quote
  #3  
Old 26-02-2010
Member
 
Join Date: May 2008
Posts: 2,383
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
__________________
The FIFA Manager 2009 PC Game
Reply With Quote
  #4  
Old 26-02-2010
Member
 
Join Date: Feb 2008
Posts: 1,848
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.
Reply With Quote
  #5  
Old 26-02-2010
Member
 
Join Date: Jan 2008
Posts: 1,515
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
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags: , , , ,



Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "In which way I can use the compare() in CPP programs"
Thread Thread Starter Forum Replies Last Post
Remove Wrong Programs from Recommended Programs List in Windows michaels Customize Desktop 7 14-08-2009 09:03 PM
Uninstall Programs That Are Not Appeared in Add or Remove Programs List DANIEL 602 Tips & Tweaks 0 10-01-2009 08:37 PM
Can't remove or modify programs from control panel Add/Remove Programs any more.. gemss Windows XP Support 3 15-11-2008 07:27 PM
Unknown Programs - i.e. "BufferChm" from Add or Remove Programs CostasD Windows XP Support 2 24-09-2007 06:19 AM
My Add/Remove Programs list missing several installed programs Fedlix Windows XP Support 3 05-09-2006 05:34 AM


All times are GMT +5.5. The time now is 07:17 PM.