comparing strings c++
C++
// CPP code perform relational
// operation using compare function
#include <iostream>
using namespace std;
void compareFunction(string s1, string s2)
{
// comparing both using inbuilt function
int x = s1.compare(s2);
if (x != 0)
cout << s1 << " is not equal to "
<< s2 << endl;
if (x > 0)
cout << s1 << " is greater than "
<< s2 << endl;
else
cout << s2 << " is greater than "
<< s1 << endl;
}
// Main function
int main()
{
string s1("Geeks");
string s2("forGeeks");
compareFunction(s1, s2);
return 0;
}
int compare (const string& str) const;
// CPP code to implement relational
// operators on string objects
#include <iostream>
using namespace std;
void relationalOperation(string s1, string s2)
{
if (s1 != s2)
cout << s1 << " is not equal to "
<< s2 << endl;
if (s1 > s2)
cout << s1 << " is greater than "
<< s2 << endl;
else
cout << s2 << " is greater than "
<< s1 << endl;
}
// Main function
int main()
{
string s1("Geeks");
string s2("forGeeks");
relationalOperation(s1, s2);
return 0;
}
Also in C++:
- Title
- string to number in c++
- Category
- C++
- Title
- basic ex of maps in c++
- Category
- C++
- Title
- Get handle in C++
- Category
- C++
- Title
- popualte an array c++
- Category
- C++
- Title
- random number generator c++
- Category
- C++
- Title
- tokenize string c++
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- c++ stream string into fiel
- Category
- C++
- Title
- ternary operator c++
- Category
- C++
- Title
- c++ set console title
- Category
- C++
- Title
- c++ call method in same class
- Category
- C++
- Title
- c++ char print fixed
- Category
- C++
- Title
- date to string c++
- Category
- C++
- Title
- c++ initialize array
- Category
- C++
- Title
- c++ parse int
- Category
- C++
- Title
- pass ss tream as parameter c++
- Category
- C++
- Title
- how to check datatype of a variable in c++
- Category
- C++
- Title
- timer in c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- powers of 2 in cpp
- Category
- C++
- Title
- primeros numeros primos
- Category
- C++
- Title
- how to add a number after each number in an array with a for loop in C++
- Category
- C++
- Title
- vector in c++ class
- Category
- C++
- Title
- how are graphics in games made
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- c++ get type name of object
- Category
- C++
- Title
- basic cpp programs
- Category
- C++
- Title
- c++ unittest in ros
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- inverser les éléments d'un tableau manuellement en c++
- Category
- C++
- Title
- how to initialize a vector in c++
- Category
- C++
- Title
- c++ argv
- Category
- C++
- Title
- arrow operator c++
- Category
- C++
- Title
- lopping over an array c++
- Category
- C++
- Title
- print matrix c++
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- how to append two vectors in c++
- Category
- C++
- Title
- c++ initialise array
- Category
- C++
- Title
- c++ class constructor
- Category
- C++
- Title
- what is a header in c++
- Category
- C++
- Title
- c++ vector constructors
- Category
- C++
- Title
- -> cpp
- Category
- C++
- Title
- c++ read matttrix from text file
- Category
- C++
- Title
- c++ char to string
- Category
- C++
- Title
- rgb(100,100,100,0.5) validation c++
- Category
- C++
- Title
- how to print nth palindrome number in c++
- Category
- C++
- Title
- how to sort a vector in c++
- Category
- C++
- Title
- basic data types in c++ hackerrank solution
- Category
- C++
- Title
- c++ modulo make it give only positive numbers
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- insert at position in vector c++
- Category
- C++
- Title
- c++ cli convert string to string^
- Category
- C++
- Title
- how to declare a vector in c++
- Category
- C++
- Title
- subarray sum in c++
- Category
- C++
- Title
- static variable in c++
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- multiset c++
- Category
- C++
- Title
- c++ printf char as hex
- Category
- C++
- Title
- compile c++ program
- Category
- C++
- Title
- how to return a vector in c++
- Category
- C++
- Title
- find upper bound c++ vector
- Category
- C++
- Title
- reverse a linked list using recursion
- Category
- C++
- Title
- c++ client service ros
- Category
- C++
- Title
- how print fload wiht 3 decimal in c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- how to know the correct class of objects cpp
- Category
- C++
- Title
- set lower bound c++
- Category
- C++
- Title
- cpp nan value
- Category
- C++
- Title
- what is order in of preeendence in float, int, char, bool
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- how to find length of string in c++
- Category
- C++
- Title
- if vector contains value c++
- Category
- C++
- Title
- fast io c++ geeksforgeeks
- Category
- C++
- Title
- c++ char define
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- foind th output c++
- Category
- C++
- Title
- error: invalid conversion from 'Node*' to 'int'
- Category
- C++
- Title
- c++ ros subscriber
- Category
- C++
- Title
- runtime error in c++
- Category
- C++
- Title
- create a dictionary cpp
- Category
- C++
- Title
- c++ delete dynamically allocated array
- Category
- C++
- Title
- c++ triple
- Category
- C++
- Title
- flushing output in c++
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- how to show c++ binary files in sublime text
- Category
- C++
- Title
- is TLE means my code is correct but taking more time to computr
- Category
- C++
- Title
- bellman ford algorithm cp algorithm
- Category
- C++
- Title
- ceil in c++
- Category
- C++
- Title
- how to check sqrt of number is integer c++
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- how to make a 2d vector in c++
- Category
- C++
- Title
- pop_back
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- ue4 c++ overlapping functions cpp setup
- Category
- C++
- Title
- git branch in my bash prompt
- Category
- C++
- Title
- cpp how to create an object of template class
- Category
- C++
- Title
- euler's totient function c++
- Category
- C++