0% found this document useful (0 votes)
8 views1 page

Notes 20240919201146

The document contains a C++ program that prints the string 'Hello Dinesh' with each character displayed in a different color using ANSI escape codes. It defines a function to handle the colored output and cycles through a predefined array of color codes. The program demonstrates basic string manipulation and console output in C++.

Uploaded by

aswinpramod082
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views1 page

Notes 20240919201146

The document contains a C++ program that prints the string 'Hello Dinesh' with each character displayed in a different color using ANSI escape codes. It defines a function to handle the colored output and cycles through a predefined array of color codes. The program demonstrates basic string manipulation and console output in C++.

Uploaded by

aswinpramod082
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

09.

19 8:11 PM
#include <iostream>
#include <string>

// Function to print colored text using ANSI escape codes


void printWithColor(const std::string& text, const std::string& colorCode) {
std::cout << "\033[" << colorCode << "m" << text << "\033[0m"; // Reset color
after printing
}

int main() {
// ANSI color codes
std::string colors[] = {
"31", // Red
"32", // Green
"33", // Yellow
"34", // Blue
"35", // Magenta
"36", // Cyan
"91", // Light Red
"92", // Light Green
"93", // Light Yellow
"94" // Light Blue
};

// The string to print


std::string message = "Hello Dinesh";

// Print each character in a different color


for (size_t i = 0; i < message.length(); ++i) {
std::string color = colors[i % 10]; // Cycle through the color codes
printWithColor(std::string(1, message[i]), color);
}

std::cout << std::endl; // Move to the next line after printing

return 0;
}

You might also like