【发布时间】:2011-05-28 06:05:40
【问题描述】:
错误的位置在下面的评论中指出。请帮助解决此问题。
#include<iostream.h>
#include<string.h>
#include<stdlib.h>
class String
{
private:
enum{sz=80};
char str[sz];
public:
String()
{
strcpy(str,"");
}
String (char s[])
{
strcpy(str,s);
}
void display() const
{
cout<<str;
}
String operator +(String ss) const
{
String temp;
if(strlen(str) + (strlen(ss.str) < sz)
{
strcpy(temp.str,str);
strcat(temp.str , ss.str);
} // Error is reported here!
else
{
cout<<"\nstring overflow";
exit(1);
}
return temp;
}
};
int main()
{
String s1="\nMerry christmas";
String s2="happy new year";
String s3;
s1.display();
s2.display();
s3.display();
s3=s1+s2;
s3.display();
cout<<endl;
return 0;
}
【问题讨论】:
-
你用什么来编辑你的源代码?一个好的编辑器通常会在视觉上为您指明正确的方向。
-
你知道标准库
string类,对吧?
标签: c++ compiler-errors