char words.

Hello this is my code


#include <iostream>
char x;
using namespace std;

int main()
{
cout << "sEleverna\n";
cin >> x;

if ( x == (char)'subject')
cout << "Du har rätt\n";

system("pause");
return 0;


}


What i want to do is to make like for example if i write subject then the if will be correct. but it doesnt seem to work with the 'subject' only 's' how can i make a char contain long words? or is there some other way?
A char is a single character.

If you want a string, use C++ strings.

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

std::string x;

int main()
{
std::cout << "sEleverna\n";
std::cin >> x;

if ( x == "subject")
std::cout << "Du har rätt\n";


return 0;


}
Thanks alot!
Topic archived. No new replies allowed.