Witam,
Oto polecenie do programu : class String {char texe[256]}; napisać operator+=, operator[], operator=. Ja dorobiłem do tego konstruktor w celu łatwego sprawdzenia ale dodaje mi spacje i jakiego krzaczka po słowie "elo". Nie wiem czy mi mózg przestał już pracować czy co ale nie bardzo mogę zauważyć błąd. Z góry dziękuję :)
#include <cstdlib>
#include <iostream>
using namespace std;
class String
{
public:
char text[256];
unsigned pos;
//public:
String(char *word)
{
int i = 0;
while (word[i] != '\0')
{
text[i] = word[i];
i++;
}
}
char operator[](unsigned n)
{
return text[n];
}
void operator+=(String s)
{
for (int i = pos; i < 256; i++)
text[i] = s[i - pos];
}
void operator=(String s)
{
for (int i = 0; i < 256; i++)
text[i] = s[i];
}
friend ostream& operator<<(ostream& out, String word)
{
int i = 0;
while (word[i] != '\0')
{
out << word[i];
i++;
}
return out;
}
};
int main()
{
String word("elo");
String word2("bieda");
cout << word << word2 << endl;
system("PAUSE");
return 0;