Menu

Color Printf?

2005-11-19
2012-09-26
  • Nobody/Anonymous

    Hi, i'm new on this forum.
    My simple and only questions is:
    Can I crate a color printf (cprintf on turbo C) on dev c++?
    tks ^^

     
    • Anonymous

      Anonymous - 2005-11-21

      The MSDN link posted right after the "WriteConsoleOutput" post IS the documentation for WriteConsoleOutput(), so not much searching required!

      I beleive that the 'c' in cprintf() stands for "console" not "color". It outputs direct to the console in DOS based systems, whereas printf() may be redirected to any stream io device.

      Clifford

       
    • Nobody/Anonymous

      well....maybe my I.E cant open the page, but the MSDN link wont open here(I tested on firefox too)

       
    • Nobody/Anonymous

      The link I posted still works, and the code does as well....I tested it before I told you about it.

      ;)

      Wayne

       
    • Nobody/Anonymous

      that's irony,for quite some time MSDN pages contained extra code so that they would only be properly displayed in IE :-)

       
    • Nobody/Anonymous

      Humm ok guys, I'll read somethings here
      by the way, this example http://www.daniweb.com/code/showsnippet.php?codeid=83 , it won't work on Dev C++.
      tks ^^

       
      • Nobody/Anonymous

        Actually, as I stated earlier, it does work.

        I always compile and run such examples before I post a link to it.

        What problem did you run into?

        Wayne

         
        • Nobody/Anonymous

          My Basic 3

          I am running Dev version 4.9.9.2 on XP Pro, the code (cut and paste job, no alterations) is

          // color your text in Windows console mode
          // colors are 0=black 1=blue 2=green and so on to 15=white
          // colorattribute = foreground + background * 16
          // to get red text on yellow use 4 + 1416 = 228
          // light red on yellow would be 12 + 14
          16 = 236
          // a Dev-C++ tested console application by vegaseat 07nov2004

          include <iostream>

          include <windows.h> // WinApi header

          using namespace std; // std::cout, std::cin

          int main()
          {
          HANDLE hConsole;
          int k;

              hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
          
              // you can loop k higher to see more color choices
              for(k = 1; k &lt; 255; k++)
              {
                      // pick the colorattribute k you want
                      SetConsoleTextAttribute(hConsole, k);
                      cout &lt;&lt; k &lt;&lt; &quot; I want to be nice today!&quot; &lt;&lt; endl;
              }
          
              cin.get(); // wait
              return 0;
          

          }

          Here is my log:

          Compiler: Default compiler
          Executing g++.exe...
          g++.exe "C:\mycstuff\testit.cpp" -o "C:\mycstuff\testit.exe" -I"C:\Dev-Cpp\lib\gcc\mingw32\3.4.2\include" -I"C:\Dev-Cpp\include\c++\3.4.2\backward" -I"C:\Dev-Cpp\include\c++\3.4.2\mingw32" -I"C:\Dev-Cpp\include\c++\3.4.2" -I"C:\Dev-Cpp\include" -L"C:\Dev-Cpp\lib"
          Execution terminated
          Compilation successful

          And it changes foreground and background colors as expected when run.

          Note that this is C++ code, if you name it something.c, it will try to compile as C code, and that will not work.

          Wayne

           
    • Nobody/Anonymous

      The mayor error is this: "iostream: No such file or directory."
      The point is, i have the iostream on the header past, so why won't compile?
      PS:My version is 4.9.8

       
      • Nobody/Anonymous

        There was a reason why I posted MY basic 3. ;)

        Please post yours - see the thread titled "Please Read Before Posting a Question" if you are unsure what they are.

        Wayne

         
    • Nobody/Anonymous

      "WriteConsoleOutput"

       
    • Nobody/Anonymous

       
    • Nobody/Anonymous

      What do you mean whit "WriteConsoleOutput"
      give me some examples please ^^
      tks

       
      • Wayne Keen

        Wayne Keen - 2005-11-21

        When someone gives you a keyword, and you don't know what it is, you first stop should be google (or your favorite search engine), not posting back and asking what the term is.

        I am not trying to be mean, simply pointing out the power of trying to learn things on your own.

        Wayne

         
    • Nobody/Anonymous

      ...you don't have to know everything, the only thing everybody should really be able to do is RESEARCH, the internet makes this extremely simple nowadays, so use the tools at your hands to your advantage.

      Mike

       
    • Nobody/Anonymous

      This is an example you might find intersting to play with:

      http://www.daniweb.com/code/showsnippet.php?codeid=83

      (It works for printf too)

      Wayne

       
    • Anonymous

      Anonymous - 2005-11-23

      Try this: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dllproc/base/console_reference.asp

      All you had to do was click up-one-level on the side bar, or even select "WriteConsoleOutput" from the sidebar to get there directly.

      The URL appears to be correct, but MSDN seems to be blocking a direct link to it.

      Clifford

       

Log in to post a comment.