重载运算符这首题哪儿错了?

来源:百度知道 编辑:UC知道 时间:2024/05/02 06:55:39
很有可能是编译器问题!我用的VC++6.0
书上的例题也说过.我检查这首题很久.始终发现不了错误.
提示错误:std不存在或不属于namespace;

#include<iostream.h>
#include<string.h>
using namespace std;
class String
{public:
String() {p=NULL;}
String(char *p1):p(p1){}
friend bool operator >(String &s1,String &s2);
void print() {cout<<p<<endl;}
private:
char *p;
}s1("Hello"),s2("China");

bool operator >(String &s1,String &s2)
{if(strcmp(s1.p,s2.p)>0) return true;
else return false;}

int main()
{cout<<(s1>s2);
return 0;}
结果是将前2行改为
#include<iostream.h>
删掉(using namespace std;)

这个程序没有问题。我在.NET下尝试成功的,将语句
#include <iostream.h>改为
#include <iostream>
最后保存为xxx.cpp,编译运行成功。

多了分号。而且要写程序最前面!谢谢!
using namespace std
我这边是用VC的是好的。不知道你怎么弄的。二楼的也肯定不对。

C++里也用using namespace std; 这个?不是C#中才有的吗?