64,441
社区成员
发帖
与我相关
我的任务
分享
#include<iostream.h>
using namespace std;
就会有如下错误:
而换成#include<iostream.h>时就可以通过,这又是为什么[/quote]
C++下建议使用#include<iostream>
iostream.h是为了向下兼容而设置的[/quote]
写错了,应该是如果我用的是
#include<iostream>
using namespace std;
就会报错;
如果用#include<iostream.h>
就可以通过[/quote]
你试下在你Str构造函数中加上explicit,我怀疑是你这个和标准里string的operator+重复了[/quote]行不通。。。我再发个贴问问好了,谢谢#include<iostream.h>
using namespace std;
就会有如下错误:
而换成#include<iostream.h>时就可以通过,这又是为什么[/quote]
C++下建议使用#include<iostream>
iostream.h是为了向下兼容而设置的[/quote]
写错了,应该是如果我用的是
#include<iostream>
using namespace std;
就会报错;
如果用#include<iostream.h>
就可以通过[/quote]
你试下在你Str构造函数中加上explicit,我怀疑是你这个和标准里string的operator+重复了#include<iostream.h>
using namespace std;
就会有如下错误:
而换成#include<iostream.h>时就可以通过,这又是为什么[/quote]
C++下建议使用#include<iostream>
iostream.h是为了向下兼容而设置的[/quote]
写错了,应该是如果我用的是
#include<iostream>
using namespace std;
就会报错;
如果用#include<iostream.h>
就可以通过#include<iostream.h>
using namespace std;
就会有如下错误:
而换成#include<iostream.h>时就可以通过,这又是为什么[/quote]
C++下建议使用#include<iostream>
iostream.h是为了向下兼容而设置的#include<iostream.h>
using namespace std;
就会有如下错误:
#include<iostream>
#include<string>
using namespace std;
class Str
{
int length;
char *p;
public:
Str()
{
p=new char[100];
}
Str(char *s)
{
p=new char [100];
strcpy(p,s);
}
Str(const Str &obj)
{
p=new char [100];
strcpy(p,obj.getp());
}
~Str()
{
delete []p;
}
friend Str operator+(const Str &s1,const Str &s2);
void operator =(const Str &obj);
char* getp()const
{
return p;
}
void setp(char *s)
{
strcpy(p,s);
}
void show()
{
length=strlen(p);
cout<<"length="<<length<<" "<<p<<endl;
}
};
Str operator + (const Str &s1,const Str &s2) //报错处
{
Str temp;
strcpy(temp.getp(),s1.getp());
strcat(temp.getp(),s2.getp());
return temp;
}
void Str::operator =(const Str &obj)
{
strcpy(p,obj.getp());
}
int main()
{
char s1[100],s2[100];
cin.getline(s1,100);
cin.getline(s2,100);
Str A(s1);
Str B(s2);
Str C;
C=A+B;
C.show();
return 0;
}