+ 8
strcmp()
why Char[] not string
6 Answers
+ 17
By syntax it is
strcmp(const char *leftStr, const char *rightStr );
which means it will compare character by character not the entire string.
This method works in to forms
1. Character array
2. Character pointer
+ 4
Given two c++ strings, you want to compare them using strcmp() but it only accepts arguments of const char *?
If that's the case, you can retrieve a C-style string from a C++ string trough mystring.c_str() and compare it that way.
Example:
string str1 = "Hello, world!";
string str2 = "Hello, world!";
if (!strcmp(str1.c_str(), str2.c_str())
std::cout << "The strings are equal." << std::endl;
else
std::cout << "The strings are not equal." << std::endl;
+ 3
good stuff đŸ
+ 1
String s=Wanna ghana
0
you can use string too, just need to include string with #include<string.h>