Error C2440

closed account (LAfSLyTq)
Here my code

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

int main()
{
	char x;
	char a;
	char y;

	cin>>a;
	if(a = "Text here")
	{
		cout<<"Text 1 here"<<endl;
	}
	return 0;
}


i already know that its probably because i am misusing "char" but i tried to use string and it gives me porblems too, what should i use?
Use int x; int a; int y;
closed account (LAfSLyTq)
still got the same error... =\
closed account (LAfSLyTq)
Here is my current code, i am still having the error.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
#include <iostream>
#include <string>
#include <ctime>
#include <cstdlib>
using namespace std;

int main()
{
	char x;
	int a;
	char y;

	cin>>a;
	if(a = "Text here")
	{
		cout<<"Text 1"<<endl;
	}
	return 0;
}
1.) You should not be using = in your if statement; that is assignment. You want ==, which is comparison.

2.) You are trying to compare a integer to a string of characters. You can't do that. In your original example, you were trying to compare a single character to a string. You can't do that either.

3.) Even if a were a string of characters, you can't use == to compare them. You would need to use strcmp(), or simply use std::strings (you have the header already) instead.
closed account (LAfSLyTq)
thank you very much for your help, use strings instead. =]
Topic archived. No new replies allowed.