+ 8

strcmp()

why Char[] not string

2nd Jan 2018, 3:34 PM
I'm_Groot
I'm_Groot - avatar
7 Respostas
+ 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
2nd Jan 2018, 4:30 PM
Seetha
Seetha - avatar
2nd Jan 2018, 4:09 PM
I'm_Groot
I'm_Groot - avatar
+ 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;
2nd Jan 2018, 4:58 PM
Cluck'n'Coder
Cluck'n'Coder - avatar
+ 3
good stuff 💾
3rd Jan 2018, 7:42 AM
Manual
Manual - avatar
+ 1
String s=Wanna ghana
2nd Jan 2018, 6:44 PM
Xander Keylis
0
you can use string too, just need to include string with #include<string.h>
2nd Jan 2018, 3:55 PM
Vukan
Vukan - avatar