Welcome, guest! Login / Register - Why register?
Psst.. new poll here.
Psst.. new forums here.
Microsoft is blocking us again (TY IP Reputation!) so just use oauth login instead. :)

Paste

Pasted as C++ by sq ( 16 years ago )
#include <iostream>
#include <string.h>
#include <stdio.h>

using namespace std;

class stroka {
private:

char* znachenie;
int dlina;
public:

stroka()
{//Конструктор по умолчанию
znachenie = new char;
znachenie = 0;
dlina = 0;
}

stroka(const char* ch)
{//Конструктор с параметром char *
int u=0;
dlina = strlen(ch)+1;
znachenie = new char[dlina];
while (u<dlina)
{
znachenie[u] = ch[u];
u++;
}
}

stroka(stroka& orig)
{//Конструктор копирования
int u = 0;
dlina = orig.dlina;
znachenie = new char[dlina];
while (u < dlina)
{
znachenie[u] = orig.znachenie[u];
u++;
}
}

stroka& operator=(const stroka &orig;)
{//Оператор присваивания
int u=0;
dlina = orig.dlina;
delete[] znachenie;
znachenie = new char[dlina];
while (u<=dlina)
{
znachenie[u] = orig.znachenie[u];
u++;
}
return *this;
}

stroka& operator+=(const stroka &other;)
{
int u=0;
char *bufer = new char [dlina+other.dlina-1];
while (u < dlina)
{
bufer[u]=znachenie[u];
u++;
}
u=0;
while (u < other.dlina)
{
bufer[u+dlina-1] = other.znachenie[u];
u++;
}
delete[] znachenie;
u = 0;
znachenie = new char[other.dlina+dlina-1];
while (u < other.dlina+dlina-1)
{
znachenie[u] = bufer[u];
u++;
}
delete[] bufer;
return *this;
}

int print()
{
cout << znachenie << "\n";
return 0;
}
operator char*()
{
return znachenie;
}

~stroka(){//Деструктор
delete [] znachenie;
}
};

int main()
{
stroka first = "Okay\n";
cout<<first;

stroka second = "ololo";

second += first;
cout<<second<<"\n";
//stroka fourth;
//fourth.print();
return 0;
}

 

Revise this Paste

Children: 22979
Your Name: Code Language: