Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4

Thread: Text Color C++

  1. #1
    Regular Coder
    Join Date
    Mar 2006
    Posts
    258
    Thanks
    1
    Thanked 2 Times in 2 Posts

    Text Color C++

    I'm trying to add color to some text in my application, but I'm getting a nasty error:
    Code:
    #include <windows.h>
    #include <iostream>
    #include <cstdlib>
    #include <conio.h>
    #include <stdio.h>
    #include <sstream>
    using namespace std;
     
      
      main(){
    textcolor (YELLOW);
    textbackground (BLUE);
    cprintf ("Im yellow text on a nice blue background!");
      }
    error:
    Code:
    11 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `YELLOW' undeclared (first use this function) 
    11 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `textcolor' undeclared (first use this function) 
    12 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `BLUE' undeclared (first use this function) 
    12 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `textbackground' undeclared (first use this function) 
    13 C:\Documents and Settings\Boris\Desktop\ruleta zero\test.cpp `cprintf' undeclared (first use this function)
    Of course, I don't know what I'm doing. I just got the function from somewhere on the net, and it said the conio.h header should be used. Any ideas?

    I'm using Dev-C++

    EDIT: Never Mind, the problem is that conio.h is very limited in Dev-C++. Solution is to get a Borland C++ compiler.
    Last edited by daniel_g; 06-15-2007 at 06:57 PM.

  • #2
    Senior Coder
    Join Date
    Apr 2003
    Location
    England
    Posts
    1,192
    Thanks
    5
    Thanked 13 Times in 13 Posts
    It seems that conio is compiler specific. It is best to avoid such things (I always make sure my code compiles on gcc/g++ with gnu or mingw)

  • #3
    New to the CF scene
    Join Date
    May 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,
    There is functions to work with text consoles in Win32. You can search them in the SDK from Microsoft or, I think in the next help file:
    ftp://ftp.cs.virginia.edu/pub/lcc-win32/win32hlp.exe
    You can, even, work with the mouse.
    One function that you can employ is:

    BOOL SetConsoleTextAttribute(

    HANDLE hConsoleOutput, // handle of console screen buffer
    WORD wAttributes // text and background colors
    );

    You'll need more than this.

  • #4
    Regular Coder
    Join Date
    Mar 2006
    Posts
    258
    Thanks
    1
    Thanked 2 Times in 2 Posts
    Thank you for the replies.
    For that task I was specifically asked to work with Borland C++, and the conio library. I got confused because Dev-C++ did include conio.h, but it was very limited.
    Dev-C++ does offer a 'conio2' library that includes all functions from Borland, and can be downloaded under updates, however, it can get a little bit tricky to make it work, so the easiest way to make it all work was to get a Borland specific compiler.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •