how to compare two char* in c++
#include <string.h>
...
if (strcmp(firstSTR, secondSTR) == 0) {
// strings are equal
...
} else {
// strings are NOT equal
}
how to compare two char* in c++
#include <string.h>
...
if (strcmp(firstSTR, secondSTR) == 0) {
// strings are equal
...
} else {
// strings are NOT equal
}
how to compare strings in c++
// comparing apples with apples
#include <iostream>
#include <string>
int main ()
{
std::string str1 ("green apple");
std::string str2 ("red apple");
if (str1.compare(str2) != 0)
std::cout << str1 << " is not " << str2 << 'n';
if (str1.compare(6,5,"apple") == 0)
std::cout << "still, " << str1 << " is an applen";
if (str2.compare(str2.size()-5,5,"apple") == 0)
std::cout << "and " << str2 << " is also an applen";
if (str1.compare(6,5,str2,4,5) == 0)
std::cout << "therefore, both are applesn";
return 0;
}
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us