注册 登录
编程论坛 C++教室

vc++中的strcmp函数问题

wghost 发布于 2009-11-04 10:41, 3374 次点击
//////////////////////////////////////////////////////////////////////
#include "STRING.h"
#include<iostream.h>


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

STRING::STRING()
{
 p=NULL;
}

STRING ::STRING(char *str)
{
    p=str;
}

void STRING:: display()
{
    cout<<p;
}
bool operator>( STRING & string1,STRING & string2)
{
    if(strcmp(string1.p,string2.p)>0)
          return true;
    else
          return false;
}

bool operator <(STRING &string1,STRING &string2)
{
    if(strcmp(string1.p,string2.p)<0)
          return true;
    else
          return false;
}

bool operator== (STRING &string1,STRING &string2)
{
    if(strcmp(string1.p,string2.p)==0)
          return true;
    else
          return false;
}

STRING::~STRING()
{

}
编译时提示我:
D:\c++\ex4_441\STRING.cpp(28) : error C2065: 'strcmp' : undeclared identifier
谁知道应包含什么头文件,cstring和string.h 我已经试过了,高手帮忙
8 回复
#2
bhbh2009-11-04 11:26
#includes<iostream>
using namespace std;
这么修改一下或许有用
#3
qlc002009-11-04 11:54
你再加一个#include<string.h>试下!
#4
wghost2009-11-06 09:27
我在类中声明了运算符函数的友元,如果使用
#include<iostream>
using namespace std;
会出错。而且用
#include<sting.h>
也不行。
#5
qlc002009-11-06 11:03
你给你的头文件和实现函数也发过来我帮你看下!
#6
wghost2009-11-07 21:02
lass STRING  
{
public:
    STRING();
    STRING(char *str);
    friend bool operator >(STRING &string1,STRING &string2);
    friend bool operator<(STRING &string1,STRING &string2 );
    friend bool operator==(STRING &string1,STRING &string2);
    void display();
    virtual ~STRING();
private:
    char *p;
};
#include "STRING.h"
#include<iostream.h>


//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

STRING::STRING()
{
 p=NULL;
}

STRING ::STRING(char *str)
{
    p=str;
}

void STRING:: display()
{
    cout<<p;
}
bool operator>( STRING & string1,STRING & string2)
{
    if(strcmp(string1.p,string2.p)>0)
          return true;
    else
          return false;
}

bool operator <(STRING &string1,STRING &string2)
{
    if(strcmp(string1.p,string2.p)<0)
          return true;
    else
          return false;
}

bool operator== (STRING &string1,STRING &string2)
{
    if(strcmp(string1.p,string2.p)==0)
          return true;
    else
          return false;
}

STRING::~STRING()
{

}
#7
ml2325282009-11-09 17:19
头文件<string.h>
#8
ml2325282009-11-09 17:21
main()函数所在源文件 也加上头文件


[ 本帖最后由 ml232528 于 2009-11-9 17:24 编辑 ]
#9
wghost2009-11-10 13:50
还是不行,是不是环境的问题啊?
1