Displaying letters slowly on screen. Typing effect?

I am doing a little assignment and came up with a grand idea (lol) of doing a typing effect on the screen, if it is at all possible.

For example, in movies when a computer is talking to a human, you see the letters typing out letter by letter on the screen with a blinking cursor at the end.

"Hello Bob..._"

Is it possible to do this type of effect with C++?
I was thinking of some kind of looping but, with speeds of processors now-a-days that wouldn't help slow down the display of text on the screen.
@docarchy

If your using the console, here are my suggestions. Add #include <windows.h> , if it's not there already. That is for using the Sleep command. It's used as Sleep(1000) That gives a 1 second delay. Play around with the 1000 till you get the delay you want. For printing letter by letter, yes, use a loop.
As
1
2
3
4
5
6
7
8
9
10
11
12
13
int main()
{
string hello = "Hello Bob. Let's get\nprogramming in C++";
int x=0;
while ( hello[x] != '\0')
{
	cout << hello[x];
	Sleep(500);
	x++;
};
	cout << "\n\nEnd of message.." << endl << endl;
	return 0;
}


EDIT: If you want a sound when each letter is printed, add
1
2
if ( hello[x]!= ' ' && hello[x]!= '\n')
		Beep(850, 300);
between the cout, and the Sleep command.
Last edited on
Perfect! Thanks whitenite! :D
For a little bit more added "realism", you could add a bit of randomness.

Sleep(250 + rand() % 250);

(having seeded the random number generator as usual)

Andy
Last edited on
Or maybe delay (sleep) longer after a space.
1
2
3
4
5
6
for( int i = 0; msg[i] != '\0'; i++ ) {
	Sleep(200);
	cout << msg[i];
	if( msg[i] == ' ' )
		Sleep(150);
}
Or both?

1
2
3
4
5
6
7
for( int i = 0; msg[i] != '\0'; i++ ) {
	if( msg[i] == ' ' )
		Sleep(300 + rand() % 500);
	else
		Sleep(250 + rand() % 250);
	cout << msg[i];
}
c++ is not getting in full screen in win 7
it shows the message " the system does not support full screen mode " when i press alt+enter....
how can i get full screen ?
Topic archived. No new replies allowed.