标题问题是:试定义一个字符串类string,使其至少具有内容(contents)和长度(length)两个数据成员,并具有展现字符串,求字符串长度,给原字符串后添加一个字符串等功用.
我写了一个法式,但错误百出.:-(
#includeiostream.h
#includestring.h
class string
private :
char *content;
int length;
public:
void puts(str)
puts(content);
void strlen(str)
strlen(content);
void shows()
coutcontentendl;
void putin()
cincontent;
void strcat( str1,str2)
strlen(str);
void main()
string str1,str2;
str1.putin ();
str1.shows();
str1.puts(content);
str1.strlen(content);
str2.putin ();
strcat(str1,str2);
期看能有人帮帮手啊,指点一下;
编译后的错误如下:
C:\Program Files\Microsoft Visual Studio\MyProjects\y\y2.cpp(10) : error C2061: syntax error : identifier ’str’
C:\Program Files\Microsoft Visual Studio\MyProjects\y\y2.cpp(14) : error C2061: syntax error : identifier ’str’
C:\Program Files\Microsoft Visual Studio\MyProjects\y\y2.cpp(27) : error C2061: syntax error : identifier ’str1’
C:\Program Files\Microsoft Visual Studio\MyProjects\y\y2.cpp(38) : error C2065: ’content’ : undeclared identifier
C:\Program Files\Microsoft Visual Studio\MyProjects\y\y2.cpp(41) : error C2664: ’strcat’ : cannot convert parameter 1 from ’class string’ to ’char *’
No user-defined-conversion operator available that can perform this conversion, or the operator cannot be called
Error executing cl.exe.