HELP CHAR

1
2
3
4
5
6
7
8
9
10
11
12
#include <iostream>
using namespace std;

int main() {
char a[]= "aaaa" ;
char pass[]="aaaa";
cout << a << endl;
if ( a==pass ) 
cout << "bye" << endl;
else
cout << "hi " << endl;
return 0; }

Output is:
aaaa
hi
Why a char isnt equal to pass char??
you need to use string compare or compare each char individually
Last edited on
you are comparing pointers i believe, which are in fact different
If you use std::string instead of c strings you can compare the strings as you do now. To compare 2 c strings you can use std::strcmp
if (strcmp(a, pass) == 0)

ok i solved it :
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>
using namespace std;

int main() {
string a = "aaaa" ;
string b ="aaac";
cout << a<< endl;
if ( a==b) 
cout << "bye" << endl; 
else 
cout << "hi" << endl; 
return 0; }
Topic archived. No new replies allowed.