why does it always print not equal!Code:char a[6]="hello"; char b[6]="hello"; if(a <> b) {cout<<"not equal";}
why does it always print not equal!Code:char a[6]="hello"; char b[6]="hello"; if(a <> b) {cout<<"not equal";}
use strings like this:
#include <string>
using namespace std;
int main()
{
string h = "hello world";
string i = "hello world";
return 0;
}
First, <> is not an operator in C++. != is the operator for "not equal to"Originally posted by krappykoder
why does it always print not equal!Code:char a[6]="hello"; char b[6]="hello"; if(a <> b) {cout<<"not equal";}
Also, you can't compare char arrays like that directly, you'd have to use a function like strcmp in the string header, or you can use a string class.
if you want to get it to work, then #include<string>
then type
using namespace std;
then do
char a[6]="hello";
char b[6]="hello";
if( strcmp( a, b ) )
{cout<<"not equal";}
>>string h = "hello world";
>>string i = "hello world";
When ever i do this and i include string.h it gives me string undifiend can anyone post me a copy of there string header file thnx
-Devouring One-
Dev C++
Win XP/2k/98
I DO NOT TAKE CLASSES I DONT GET HOMEWORK THIS IS NOT A HOMEWORK QUESTION!!!
He's lean he's keen... He's the spank machine!
that's because you have to do
#include<string>
using std::string;
notice it's string not string.h
Also, the typedef for string is in the std namespace