|
发表于 2018-1-26 18:01:05
|
显示全部楼层
只是能通过编译
- #include<iostream>
- #include<string.h>
- using namespace std;
- #define maxsize 100
- class str
- {
- private:
- char gro[maxsize];
- int length;
- public:
- str();
- str operator+(str tt);
- void showing();
- };
- int main()
- {
- str group1, group2, group;
- group = group1 + group2;
- group.showing();
- return 0;
- }
- str::str()
- {
- str s1;
- cin >> s1.gro;
- length = strlen(s1.gro);
- strcpy(gro, s1.gro);
- }
- str str::operator+(str tt)
- {
- /*cin >> s2;
- strcpy(gro, s2.gro);
- length = strlen(s2.gro);
- str temp;
- int length1;
- length1 = strlen(gor) + strlen(s2.gro) + 1;
- if(length1>maxsize)
- {
- cout << "已超出最大限度" << endl;
- strcpy(temp.gro, s2);
- length = strlen(s2);
- cout << s2 << endl;
- }
- length = length1;
- strcat(temp.gro, s2.gro);
- return temp;*/
- return str();
- }
- void str::showing()
- {
- cout << gro << endl;
- cout << "该字符串长度为:" << length << endl;
- }
复制代码 |
|