-
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
-
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 :D. 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.
-
>>$e[31m
probably need to surround that this double quotes -- looks like Ansys.sys command.
-
> \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"
-
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
-
>>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.
-
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.