A simple question about why it always tells me character constant is too long

here is my code...

#include <iostream>
#include <string>

using namespace std;

int main()
{

int x;

cout << "welcome";

cout << " code please?";
cin >> x;

if(x=='*121#')
{
cout << "congrats";

}
else
cout << "invalid";

return 0;
}

What are you trying to do?
1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <string>

int main()
{
    std::cout << "welcome. code please? " ;
    std::string x ; // we want to read in a string
    std::cin >> x;

    // note: use double quotes " for string, single quotes ' for char
    if( x == "*121#" ) std::cout << "congrats\n" ;
    else std::cout << "invalid\n";
}
Thanks so much! I learned a lot today.
Topic archived. No new replies allowed.