I'm a newbie. For a school project, I need a typewriter, and I came down to this idea that seems good to me. But when I launch it, it says this error:
terminate called after throwing an instance of 'std::out_of_range' error
I don't know why. I think the idea is good, because when I try without the variable t
, so just putting numbers in testo.erase()
, it works, but I need to create a loop.
void typewriter(string testo, int tempo)
{
int i = testo.length();
int t = 0;
while (t<=i)
{
system ("CLS");
t=t+1;
testo.erase(t);
cout<<testo;
Sleep(tempo);
}
}