compare char* c++ code example
Example 1: c++ compare char
#include <cstring>
std::strcmp(<1st-char>,<2nd-char>)
#include <cstring>
if (std::strcmp(char_1,char_2) == 0) {
std::cout << "The char's that you compared match!" << std::endl;
}
else {
std::cout << "The char's that you compared DON'T match" << std::endl;
}
Example 2: how to compare two char* in c++
#include <string.h>
...
if (strcmp(firstSTR, secondSTR) == 0) {
...
} else {
}
Example 3: strcmp c++
#include<stdio.h>
#include<string.h>
int main()
{
char char1[] = "coucou";
char char2[] = "coucou";
if( strcmp(char1, char2) == 0 )
printf("Strings are the same");
else
prinf("Strings are differentes");
return 0;
}