zad27
ocb?unknown
d
5 years ago
731 B
10
Indexable
import std.stdio;
class Bufor
{
char[] buffer;
int bufSize = 5;
int curPos;
this() {
curPos = 0;
buffer = new char[bufSize];
}
this(int newBufSize) {
bufSize = newBufSize;
this();
}
void czytaj() {
writeln(buffer);
}
void zapisz(string str) {
// string -> char[]
char[] strArr = str.dup;
if((curPos + strArr.length) > bufSize) {
writefln("Bufor jest za duzy, nie mozna zapisac '%s'", str);
} else {
buffer ~= str;
curPos += strArr.length;
}
}
}
void main()
{
Bufor buf = new Bufor();
buf.zapisz("ab");
buf.zapisz("cd");
buf.zapisz("ef");
buf.czytaj();
// Wypisuje
// Bufor jest za duzy, nie mozna zapisac 'ef'
// abcd
}
Editor is loading...