Related to string and char array

how can i compare an element of the char array and string with single chsracter also how to compare char array to cpp string
http://www.cplusplus.com/reference/string/string/c_str/

would help, but i don't understand much of your sentence i'm afraid.
Last edited on
how to compare char array to cpp string
Directly.
1
2
3
const char* str = "Hello";
std::string s = "Hello";
std::cout << (s == str);

element of the char array and string with single chsracter element of string
Directly
1
2
3
const char* str = "Hello";
std::string s = "o";
std::cout << (s[0] == str[4]);
thanks this means that cpp strings can also be refered character wise as

1
2
3
string a="ABC";
char b[]="ABC";
cout<<( a[0] == b[0] );


Thanks
Topic archived. No new replies allowed.