time&date + colors

This is a discussion on time&date + colors within the C++ Programming forums, part of the General Programming Boards category; Hi everyone, I'm a student ICT and my project is to make a sort of "ticket" (from a market or ...

  1. #1
    Registered User
    Join Date
    Mar 2006
    Posts
    2

    time&date + colors

    Hi everyone,
    I'm a student ICT and my project is to make a sort of "ticket" (from a market or something)
    I have almost searched the whole world 'round to find how to get time&date. Finally I found it, but it's writting in C instead c++, that's not really a problem. But now those colors... that's something else... I know their are codes like this -> \e[0;31m (for red)

    but when i compile this, it complains because "e" don't has a value...

    I'll give you all what I have

    this is the time&date

    Code:
    #include <iostream>
    #include <stdio.h>
    #include <time.h>
    #include <iomanip>
    using namespace std;
    
    int main ()
    {
      time_t rawtime;
    
      time ( &rawtime );
      setw(12);
      printf ("%s", ctime (&rawtime) );
      
      return 0;
    }
    and this is for the colors

    Code:
    // Om de kleuren te kunnen instellen is er een speciaal attribuut dat moet ingesteld worden. Deze heeft de naam: ansi.sys
    // voor meer info kan je deze website bezoeken -> http://www.pcxt-micro.com/ansi.html
    
    #include<iostream>
    using namespace std;
    int main () {
    
    cout<< $e[31m<< "Hallo C++";
    	
    cout<< [31m<< "Dit is een tweede poging!";
    
    return 0;
    }
    thx for all your respons

  2. #2
    System Novice siavoshkc's Avatar
    Join Date
    Jan 2006
    Location
    Tehran
    Posts
    1,231
    What is your OS? Windows? If so it should be a console program. You are using old DOS prompt syntax (The worst syntax I have ever seen). It wont work in windows and the way you've written it, it wont even work in DOS . If it is DOS, #include<stdlib.h> then use system() and send "prompt" command with it's arguments to shell.
    I only ask for myself, what is your native language? I saw in comments of you'r code.
    Learn C++ (C++ Books, C Books, FAQ, Forum Search)
    Code painter latest version on sourceforge DOWNLOAD NOW!
    Download FSB Data Integrity Tester.
    Siavosh K C

  3. #3
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    >>$e[31m

    probably need to surround that this double quotes -- looks like Ansys.sys command.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    > \e[0;31m
    1. you need ansi.sys loaded (for old DOS at least)
    No idea what you do if you have a win32 console.

    2. \e in a C++ program would be "\033"

  5. #5
    Registered User
    Join Date
    Mar 2006
    Posts
    2
    my compiler is cygwin (linux) what is so wrong in my code? I know it is not verry ificient written but it works. Only the colors doesn't work.
    But do you know how I should write my code (time& date) in good c++ because it's c I guess.

    Thx for your reply's

  6. #6
    Registered User
    Join Date
    Aug 2005
    Posts
    1,267
    >>do you know how I should write my code (time& date) in good c++

    there are no standard c++ classes to do that. People have written various c++ wrappers for the functions in time.h, but nothing in ansi standards for it. you might check out the boost libraries, it may have some. But boost is a bit overkill just to get c++ wrapper for time functions.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,671
    Code:
    #include <stdio.h>
    #include <stdlib.h>
    
    int main ( int argc, char *argv[] ) {
      printf( "\033[0;31mHello World\033[0m\n" );
      return 0;
    }
    Prints in red on my cygwin.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Why I only get 8 colors out of ncurses?
    By Nazgulled in forum C Programming
    Replies: 3
    Last Post: 05-08-2007, 06:06 PM
  2. Relation between material colors and light colors.
    By indigo0086 in forum Game Programming
    Replies: 3
    Last Post: 04-18-2007, 03:20 PM
  3. colors in forefox and colors in IE
    By MisterSako in forum Tech Board
    Replies: 3
    Last Post: 05-15-2006, 01:59 PM
  4. different colors
    By Paveltc in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-19-2002, 10:21 AM
  5. Text Colors
    By GaPe in forum C Programming
    Replies: 1
    Last Post: 07-11-2002, 06:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21