I was able to figure out a simple typing effect on the console without too much trouble, but then i went complex (mostly because i was bored), and now i'm stuck :P
void wait ( double seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLOCKS_PER_SEC ;
while (clock() < endwait) {}
}
void type_erase(std::string content, int placement, int backspace, double time_delay)
{
//note you need to type the string WITH the content to be erased
int length = content.length();
if (placement > length || placement < backspace){std::cout << "\nError in argument call\n";return;}
wait(time_delay);
int b;
for(int i = 0; i < length+backspace;)
{
for(i = 0; i < placement;i++)
{
char a = content[i];
std::cout << a;
wait(time_delay);
}
if(backspace > 0)
{
for(i = placement; i < placement+backspace;i++)
{
if(i == placement){wait(.15);}
wait(.05);
std::cout << "\b \b";
}
}
for(i==placement+backspace, b = placement;i<length+backspace;i++,b++)
{
wait(time_delay);
char c = content[b];
std::cout << c;
}
}
}
i get a nice big fat error if the string is long enough to need multiple lines (without a newline character) or if the string has newline characters which in either case, if the backspace part of the function is supposed to erase the newline char, it fails. I know it comes from the second nested for loop, because that's the backspace type function. Buuuut.... how would i get it to delete a newline character.
Note: if you recommend \r, you have to tell me how to input a checker to see if the previous character is a newline character as otherwise, it will screw up the rest of the effect.
You'd have to use a much more advanced method, using some OS-specific stuff (either directly, via the Windows or terminfo database, or indirectly via NCurses or the like).
fun. is there anyway to find if the previous character on the console is '\n' and if you're referring to b = placement that's done purposely instead of ==