文字列1の文字列2の出現を排除し、2つの文字列の共通部分も見つけなければなりません。ここで2つの文字列の交差と結合
は、私が試したものです:私は、コンパイラのエラーを取得していますし、また、私は私がしようとしていますかわからないです
#include "stdafx.h"
#include "stdio.h"
#include "conio.h"
#include "string.h"
class operation
{
public:
char string1[100];
char string2[50];
operation(){};
operation(char a[100], char b[50]);
operation operator+(operation);
operation operator-(operation);
operation operator*(operation);
};
operation::operation(char a[100], char b[50])
{
strcpy(string1, a);
strcpy(string2, b);
}
operation operation::operator +(operation param)
{
operation temp;
strcpy(param.string1, temp.string1);
strcpy(param.string2, temp.string2);
strcat(temp.string1, temp.string2);
return (temp);
}
operation operation::operator -(operation param)
{
operation temp;
strcpy(param.string1, temp.string1);
strcpy(param.string2, temp.string2) ;
for (int i = 0; i<strlen(temp.string2); i++)
{
temp.string1.erase(i, 1);
}
return (temp);
}
operation operation::operator *(operation param)
{
operation temp;
strcpy(param.string1, temp.string1);
strcpy(param.string2, temp.string2);
char result[50];
for(int i = 0; i<strlen(temp.string2); i++)
{
if(temp.string1.find(temp.string2[i]) != string::npos)
result = result + temp.string2[i];
}
return (temp);
}
が正しいかではありません。
次のようにエラーは以下のとおりです。
C2228: left of .erase must have class/struct/union
C2228: left of .find must have class/struct/union
実際には** C++ **のように見えますが、それは奇妙なものです。 –
Cに演算子のオーバーロードがありません。あなたはC++を意味しましたか? – dan04
この宿題はありますか?もしそうなら、そのようにタグ付けすることはできますか? – Suroot