• 13
• 15
• 19
• 27
• 9

# Newbie C++ Time/pause question

This topic is 4784 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I am currently learning C++ and am still making console based applications. If I want to make the the computer display a countdown from 10 to 1 it is no problem. My question is how can I make it count down with a 1 second delay between easch number? Is there a library function I can call like TIME_PAUSE(10) for example?. Do I need to include ctime? I would appreciate any help. Thank you.

##### Share on other sites

#include <iostream>#include <windows.h>int main(){	for(int i = 10; i > 0; i--)	{		std::cout << i << std::endl;		Sleep(1000);	}	return 0;}

##### Share on other sites
or, you could do(this one should work on any modern OS, not just Windows):
#include <cstdlib>#include <iostream>int main(int argc, char* argv[]) {    for (unsigned int i = 0; i < 10; i++) {        std::cout << i << " ";        sleep(1000);    }}

##### Share on other sites
Thank you very much.
1 more question.

Is there a function I can call to change the font color to red or yellow?

Also \n = new line and \t = tab. What is backspace so I can make the counter count in one space?

#include <iostream>#include <windows.h>using namespace std;int main(){	for(int i = 10; i > 0; i--)	{		cout << i <<  [backspace here ???] ;		Sleep(1000);	} system ("PAUSE");	return 0;}

##### Share on other sites
There's no standard function for changing the color, although if you only need it to work on windows(at least for now), you can use conio(forgot the functions you need to use though). '\b' is the backspace character, although I'm not sure if that'll work.

##### Share on other sites
check out gametutorials.com! In the Console Tutorials section there are changing color functions!