string comparison in c++
C++
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;
}
// 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;
}
Also in C++:
- Title
- date to string c++
- Category
- C++
- Title
- c++ while true
- Category
- C++
- Title
- appending a double to a string c++
- Category
- C++
- Title
- calculate factorial
- Category
- C++
- Title
- remove element by index from vector c++
- Category
- C++
- Title
- index string c++
- Category
- C++
- Title
- range based for loop c++ with reference
- Category
- C++
- Title
- friend function in c++
- Category
- C++
- Title
- longest common subsequence
- Category
- C++
- Title
- : error: ‘cont’ cannot be used as a function return (cont(cont-1))/2;
- Category
- C++
- Title
- iterate const vector
- Category
- C++
- Title
- create a bitset of 1024 bits,
- Category
- C++
- Title
- how to convert a string to a double c++
- Category
- C++
- Title
- c++ delete dynamically allocated array
- Category
- C++
- Title
- C++ If
- Category
- C++
- Title
- how to check datatype of a variable in c++
- Category
- C++
- Title
- how to output text in c++
- Category
- C++
- Title
- new in c++
- Category
- C++
- Title
- residuo en lenguaje c
- Category
- C++
- Title
- c++ give options
- Category
- C++
- Title
- get elements of 2d array c++
- Category
- C++
- Title
- max in c++
- Category
- C++
- Title
- std::iomanip c++
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- namespace c++
- Category
- C++
- Title
- pair c++
- Category
- C++
- Title
- c++ transform
- Category
- C++
- Title
- ue4 c++ overlapping functions cpp setup
- Category
- C++
- Title
- assegnare valori in c++
- Category
- C++
- Title
- flake8 max line length
- Category
- C++
- Title
- empty string c++ value
- Category
- C++
- Title
- find_if c++
- Category
- C++
- Title
- fast input output in c++
- Category
- C++
- Title
- recursion in cpp with reference
- Category
- C++
- Title
- ue4 modular character
- Category
- C++
- Title
- singleton c++
- Category
- C++
- Title
- hashset in c++
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- what is difference between ciel and floor
- Category
- C++
- Title
- int to float c++
- Category
- C++
- Title
- advanced c++ topics
- Category
- C++
- Title
- kruskal's algorithm c++ hackerearth
- Category
- C++
- Title
- console colors in C++
- Category
- C++
- Title
- capitalize first letter c++
- Category
- C++
- Title
- convert stirng to int c++
- Category
- C++
- Title
- cpp loop through object
- Category
- C++
- Title
- c++ sort vector of objects by property
- Category
- C++
- Title
- goto c++
- Category
- C++
- Title
- traverse map c++
- Category
- C++
- Title
- unordered_map c++ insert
- Category
- C++
- Title
- c++ create array
- Category
- C++
- Title
- rosrun actionlib_msgs genaction.py
- Category
- C++
- Title
- passing reference in c++
- Category
- C++
- Title
- object slicing in c++
- Category
- C++
- Title
- error: ISO C++ forbids comparison between pointer and integer [-fpermissive] if(s[i] != "b"){
- Category
- C++
- Title
- time conversion hackerrank solution in c++
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++
- Title
- Merge k sorted linked lists and return it as one sorted list.
- Category
- C++
- Title
- visual studio 2019 read and write text file c++
- Category
- C++
- Title
- iostream library in cpp
- Category
- C++
- Title
- c++ reading string
- Category
- C++
- Title
- c++ stack
- Category
- C++
- Title
- leveling system c++
- Category
- C++
- Title
- c++ variable arguments
- Category
- C++
- Title
- Qt asynchronous HTTP request
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- how to decalre a string in c++
- Category
- C++
- Title
- c++ class member initialization
- Category
- C++
- Title
- min heap declaration in c++ stl
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- c++ return multiple values
- Category
- C++
- Title
- c++ char print align
- Category
- C++
- Title
- c++ char define
- Category
- C++
- Title
- sfml base program
- Category
- C++
- Title
- C++ Student::Student()
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- how to modulo 10^9+7
- Category
- C++
- Title
- expected unqualified-id before 'if'
- Category
- C++
- Title
- COunt the number of continous subsequences such that the sum is between
- Category
- C++
- Title
- min heap priority queue c++
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- vertical traversal of binary tree
- Category
- C++
- Title
- clear qlayout
- Category
- C++
- Title
- C++ cin cout
- Category
- C++
- Title
- cloud hosting
- Category
- C++
- Title
- prefix sum array
- Category
- C++
- Title
- c++ replace n substrings
- Category
- C++
- Title
- constant variables in c++
- Category
- C++
- Title
- how to print eachh chars in string data type in c++
- Category
- C++
- Title
- All palindromic substrings
- Category
- C++
- Title
- how to get a letter from the user c++ string
- Category
- C++
- Title
- c++ code 2d block
- Category
- C++
- Title
- pass ss tream as parameter c++
- Category
- C++
- Title
- how to sort in descending order c++
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- remove item from layout
- Category
- C++
- Title
- graph using djacency matrix c++
- Category
- C++
- Title
- how to cout in c++
- Category
- C++
- Title
- change int to string cpp
- Category
- C++