am trying to make a check

am trying to make name check if it's 'Abanoup' it says it works if not it says didnot but i have a prob


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include <iostream>
using namespace std;

int main(void)
{
    char name;
    cout << "Please Submit your name??" << endl;
    cin >> name;
    if (name = "Abanoup")
    {
        cout << "worked" <<endl;
    }
    else
    {
        cout << "didnot work"<<endl;
    }
    return 0;
}

it says
error C2440: '=' : cannot convert from 'const char [8]'
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    string name;
    cout << "Please Submit your name??" << endl;
    cin >> name;
    if (name = "Abanoup")
    {
        cout << "worked" <<endl;
    }
    else
    {
        cout << "didnot work"<<endl;
    }
    return 0;
}
that would be still wrong
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    string name;
    cout << "Please Submit your name??" << endl;
    cin >> name;
    if (name = "Abanoup")
    {
        cout << "worked" <<endl;
    }
    else
    {
        cout << "didnot work"<<endl;
    }
    return 0;
}

error C2451: conditional expression of type 'std::basic_string<_Elem,_Traits,_Ax>' is illegal
read the second link i gave you
why can not i use it like this
1
2
char name;
name= "abanoup";
?
"ababnoup" is not a single character literal
Last edited on
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main(void)
{
    char name[100];
    cout << "Please Submit your name??" << endl;
    cin >> name;
    if (strcmp(name , "Abanoup")==0)
    {
        cout << "worked" <<endl;
    }
    else
    {
        cout << "didnot work"<<endl;
    }
    return 0;
}


or
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
using namespace std;

int main(void)
{
    string name;
    cout << "Please Submit your name??" << endl;
    cin >> name;
    if (name == "Abanoup")
    {
        cout << "worked" <<endl;
    }
    else
    {
        cout << "didnot work"<<endl;
    }
    return 0;
}

I am a Chinese.
I am sorry that my English is very poor,so I can only reply to you with code.
Last edited on
zhiyuanhou
I am a Chinese.
I am sorry that my English is very poor,so I can only reply to you with code.


thnx bro :)

thnx bro :)


that's all right.
Last edited on
Topic archived. No new replies allowed.