Program to display characters slowly on the console in C++ Last Updated : 28 Apr, 2021 Summarize Comments Improve Suggest changes Share Like Article Like Report The task is to write a C++ program that displays the characters of the given string slowly on the console. Approach: The given problem can be solved by using the sleep() function in C++. Header File: <windows.h> for windows<unistd.h> for Linux Syntax: Sleep(time_in_milliseconds) Random Function: The rand() function in C++ generates random numbers in the range [0, RAND_MAX]. If the random numbers are generated using the rand() function without first calling srand() the program will create the same sequence of numbers each time it is executed. Syntax: rand(void) Program 1: Below is the implementation to display characters slowly on the console in C++ using the sleep function: C++ // C++ program for the above approach #include <iostream> #include <string> #include <windows.h> using namespace std; // Driver Code int main() { // Initialize the string string S = "Hello World!"; // Traverse the given string S for (int i = 0; i < S[i]; i++) { cout << S[i]; // Waits for 200 milliseconds Sleep(200); } return 0; } Output: Program 2: Below is the implementation to display characters slowly on the console in C++ using the sleep function and the random function: C++ // C++ program for the above approach #include <iostream> #include <string> #include <windows.h> using namespace std; // Driver Code int main() { string S = "Hello World!"; for (int i = 0; i < S.length(); i++) { cout << S[i]; // random function generates // random values Sleep(200 + rand() % 200); } return 0; } Output: Comment More infoAdvertise with us Next Article Program to display characters slowly on the console in C++ K kartikeysingh51 Follow Improve Article Tags : C++ cpp-random Practice Tags : CPP Similar Reads iscntrl() in C++ and its application to find control characters In C++, iscntrl() is a predefined function used for string and character handling. cstring is the header file required for string functions and cctype is the header file required for character functions. A control character is one which is not a printable character i.e, it does not occupy a printing 3 min read Print a character n times without using loop, recursion or goto in C++ Given a character c and a number n, print the character c, n times. We are not allowed to use loop, recursion, and goto. Examples : Input : n = 10, c = 'a'Output : aaaaaaaaaa Input : n = 6, character = '@'Output : @@@@@@ In C++, there is a way to initialize a string with a value. It can be used to p 2 min read A creative C++ program to Zoom digits of an integer Write a C (or C++) program to ZOOM (magnify) the digits of an integer. It should take an integer from the user and display each digit of the integer in magnified form using some pattern. Examples: Input : 123 Output : @ @@ @ @ @@@@@ ------------------------------- @@@@ @ @ @ @ @@@@ ----------------- 4 min read Iterate over characters of a string in C++ Given a string str of length N, the task is to traverse the string and print all the characters of the given string. Examples: Input: str = "GeeksforGeeks" Output: G e e k s f o r G e e k s Input: str = "Coder" Output: C o d e r Naive Approach: The simplest approach to solve this problem is to itera 3 min read C++ Program to Print Your Own Name Printing your own name means displaying your name on the computer screen. In this article, we will learn how to print your own name using a C++ program.ExamplesInput: name = "Anmol"Output: AnmolExplanation: Given name is printed on the output screen.Input: name = "Alex"Output: AlexExplanation: Given 3 min read Like