帮忙改个C++程序

来源:百度知道 编辑:UC知道 时间:2024/06/02 05:35:43
#include "stdafx.h"
#include "string.h"
//#include "iostream.h" ?
class MyString
{
char p[30]; // 说明了一个存放字符串的字符数组
int num; // 用来统计删去的字符个数
public :
MyString operator + (MyString str1) //重载运算符" + "
{
MyString temp;
strcpy(temp.p,p);
strcat(temp.p, str1.p);
return temp;
}?

MyString operator - (MyString str1) //重载运算符" - "
{
MyString temp;
strcpy(temp.p, p);
int i = 0;
while(temp.p[i] != '\0')
{
if(temp.p[i] == str1.p[0])
{
for(int k = i;temp.p[k] != '\0';k ++)
{
temp.p[k] = temp.p[k+1];
}
num ++; //对对象本身中的num++
i --;
}
i ++;
}
temp.num = num; //对象本身的num赋值给temp对象的num
return temp;
}
void show()
{
printf(&

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
MyString operator + (MyString str1) //重载运算符" + "
{
MyString temp;
strcpy(temp.p,p);
strcat(temp.p, str1.p);
return temp;
}?

//这里多余的空格和回车都删了就好了。
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
void show_num()
{
printf("%d",number);
}
//这里应该是num
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
#include "stdafx.h"
//应改为stdio.h

修改后编译通过。

运行结果是异常的,代码里面有许多错误,你自己慢慢修改吧。

你输入的是或改变输入法了吧