If you want the program to pause so you can see the output, you can to this. At the top of your program, add:
#include <iostream>
That prepares your program for use of the cin, cout, etc.
Then before the return statement, add:
1 2
|
int variable;
cin>>variable;
|
This will cause your program to pause while it waits for input from the keyboard. When the program runs, just type any number and press enter to end it. That's probably not the only way, and certainly not the most elegant, but it's easy, so I use it. (Like I said, I'm a real beginner myself.)
As for adding time and date, I'm not sure. I've seen a few other posts that have claimed that it takes a fair amount of know-how to add them to your program. I'm currently experimenting a little with this sample I found in the Visual C++ help index:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
// crt_clock.c
// This example prompts for how long
// the program is to run and then continuously
// displays the elapsed time for that period.
//
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
void sleep( clock_t wait );
int main( void )
{
long i = 6000000L;
clock_t start, finish;
double duration;
// Delay for a specified time.
printf( "Delay for three seconds\n" );
sleep( (clock_t)3 * CLOCKS_PER_SEC );
printf( "Done!\n" );
// Measure the duration of an event.
printf( "Time to do %ld empty loops is ", i );
start = clock();
while( i-- )
;
finish = clock();
duration = (double)(finish - start) / CLOCKS_PER_SEC;
printf( "%2.1f seconds\n", duration );
}
// Pauses for a specified number of milliseconds.
void sleep( clock_t wait )
{
clock_t goal;
goal = wait + clock();
while( goal > clock() )
;
}
|
Not exactly the time and date, but I think it's somewhat relevant. I'm trying to use it as a time delay for some text output to the screen. That way for example "Hello World" would gradually be typed one letter at a time rather than just seeming to appear all at once. Anyway, I really suggest you check out the tutorials I referenced above. They'll give you a pretty good grasp of the basics.