Thread: changing the color of some partcular line or part in console program

  1. #1
    Registered User
    Join Date
    Mar 2011
    Posts
    254

    changing the color of some partcular line or part in console program

    Hi

    If I include the call function system("color 1a") changes the console's background color and text color. But I was the bold part to appear in different color, let's say, green? How do I change the color of some particular line or part in the program? I'm using Windows XP so you can tell me something Windows specific; it will do the job. Thanks your help and time. And please don't forget I'm a newbie to programming.

    Code:
    // program to calculate area of a circle
    
    #include <iostream>
    #include <cmath>
    #include <cstdlib>
    #include <windows.h>
    #include <stdlib.h>
    
    using namespace std;
    
    int main()
    
    {
        system("color 1a")
        float R, A, C;
        cout << "Enter the radius R = ";
        cin >> R;
        A = 3.142*R*R;
        C = 2*3.142*R;
        if (R >= 0)
           {
           
           cout << "Area = " << A << endl;
           cout << "Circumference = " << C << endl;
           
           }
        else
            cout << "Invalid R" << endl;
        system ("PAUSE");
    }
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,660
    Win32 Console Applications 1
    Work your way through until you get to the colours.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Mar 2011
    Posts
    254
    Thanks, Salem. It's a good link. I'm reading. I'm sure I would have some questions to you so be there to help me, please!

    Best wishes
    Jackson
    I'm an outright beginner. Using Win XP Pro and Code::Blocks. Be nice to me, please.

  4. #4
    INSANE INSIDE ekosix's Avatar
    Join Date
    May 2010
    Location
    Rio de Janeiro, Brazil
    Posts
    44
    OR, you can try NCURSES library: ncurses - Wikipedia, the free encyclopedia

    As you use Windows, you will need PDCURSES: PDCurses for Windows
    I like it very much, and if you want to know why, take a look at some apps using Ncurses: PDCurses for Windows

    If you need help with it, read its documentation: http://www.ibiblio.org/pub/Linux/doc...ming-HOWTO.pdf

    For your task, the code would be very simple too...
    Enjoy!
    liked this /\
    so like it there >

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Changing color of pen
    By Gordon in forum Windows Programming
    Replies: 4
    Last Post: 04-13-2007, 10:26 AM
  2. Replies: 2
    Last Post: 11-18-2006, 03:31 AM
  3. Color changing
    By FingerPrint in forum C++ Programming
    Replies: 5
    Last Post: 03-27-2006, 12:07 AM
  4. Changing the colors in a command line program?
    By Scott B. in forum C++ Programming
    Replies: 1
    Last Post: 08-16-2005, 10:15 PM
  5. color changing in c++
    By cppdungeon in forum C++ Programming
    Replies: 3
    Last Post: 01-17-2005, 07:20 PM