Ask coding questions

← Back to all posts
How to add color and slowprint in C++
CODER34352 (4)

I have a question.

How do you add color to a C++ text and make it go in Slow print?

Answered by Coder100 (18148) [earned 5 cycles]
View Answer
Coder100 (18148)
#include <unistd.h>
#include <iostream>

void sp(std::string str, int time) {
  for (char c : str) {
    std::cout << c << std::flush;
    usleep(time * 1000);

Time is in milliseconds, like most things.

CODER34352 (4)

Thank you,
I found all the code in your other comment about slowprint[C++]
#include <iostream>
#include <string>
#include <thread>
#include <chrono>

using namespace std;

void slow_print(const string& message, unsigned int millis_per_char=10) {
for (const char c : message) {
// flush is used to make sure the console is empty
cout << c << flush;

// Ask the thread to sleep for at least n millis.


int main() {
cout << "\033[0;34m" << endl;
slow_print("Welcome To the Karate Dojo", 50);
I found the other code about color in a website after years of looking.

Coder100 (18148)


Mark as correct answer? @CODER34352