Comparing string using compare() function in C++ || string manipulation in c++ || C++
In this, we are going see a program on string manipulation using compare function in C++ Programming Language.



The Code given below can be used in TURBO C++ Compilers: -

#include <iostream.h>
#include <string.h>
#include <conio.h>

void main()
{
    clrscr();
    char str1[50] = "Windows 10";
    char str2[50] = "Windows 8";
    int cmp = strcmp(str1,str2);
    if (cmp == 0)
    {
        cout << "Both the strings are the same";
    }
    else
    {
        cout << "Both the strings are not equal";
    }
    getch();
}

//........Coded by YASH ALAPURIA

The Code given below can be used in gcc/g++ Compilers: -

#include <iostream>
#include <stdlib.h>
#include <string.h>
using namespace std;

int main()
{
    system("cls");
    string str1 = "Windows 10";
    string str2 = "Windows 11";
    int cmp = str1.compare(str2);
    if (cmp == 0)
    {
        cout << "Both the strings are the same";
    }
    else
    {
        cout << "Both the strings are not equal";
    }
    return 0;
}

//........Coded by YASH ALAPURIA

#ENJOY CODING

Post a Comment

FOR ANY DOUBTS AND ERRORS FEEL FREE TO ASK. YOUR DOUBTS WILL BE ADDRESSED ASAP

Previous Post Next Post