I want to create a manipulator that delays between every character like if i write
delay wait = 40;
cout << wait << "Hello World!";
It should output 'H' then Sleep(40), 'e' then Sleep(40), 'l' then Sleep(40) and so on, i tried to write a class for this and here is my code:
class delay {
public:
delay(const int& amount) { // getting the amount for Sleep(...)
this->Amount = amount;
}
delay& delay::operator = (const int& amount) { // same, but for operator=
this->Amount = amount
return *this;
}
private:
ostream& m_os;
int Amount;
friend ostream& operator << (ostream& os, delay& p) { // i dont know if I even need this
p.m_os = os;
return os;
}
friend ostream& operator << (delay& p, const char* n) { // here it should do output and delay
int index = 0;
while (n[index] != '\0) {
p.m_os << n[index]; // output character
index++;
Sleep(p.Amount); // wait
}
return p.m_os;
}
};
I get errors when i try to use this code and i kinda think i have to start rewriting this from the beginning. I hope you have an idea how to realize this delay class because i tried everything i could and it doesnt work. Thank you for reading this, I hope that you can help me <3