a question regarding system time.

B

Benny Van

Hi all!
I have a question regarding a windows operating system function:
I was asked to write a small program for a homework to display the
user name and computer name and the system time out to a console
window: the display would be like:
Hello XXX(user)
Today is XXX(date)
The Time is XXX(current system time)

I was asked to use a Windows System Call---void GetLocalTime(SYSTIME
*lpSystemTime) for the time part. I have done the user and computer
name part, but I don't know how to use that call:
Here is my code for name part:

#include <iostream>
#include <windows.h>
using namespace std;

int main(int argc, char *argv[])
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
char host[500];
DWORD bufferLength;
GetComputerName(host, &bufferLength);
cout << "Host name is " << host << endl;
GetUserName(host, &bufferLength);
cout << "User is " << host << endl;
SetConsoleTitle("prog2");
}

Anyone could help me with that time part, for I really don't know how
to use that! Thank you very very much!

Sincerely,
Ben
 
J

Jim Langston

Benny Van said:
Hi all!
I have a question regarding a windows operating system function:
I was asked to write a small program for a homework to display the
user name and computer name and the system time out to a console
window: the display would be like:
Hello XXX(user)
Today is XXX(date)
The Time is XXX(current system time)

I was asked to use a Windows System Call---void GetLocalTime(SYSTIME
*lpSystemTime) for the time part. I have done the user and computer

It seems extremely straight foward. Wouldn't it just be:
SYSTIME CurrentTime;
GetLocalTime( &CurrentTime );

Set up a variable for SYSTIME (whatever that is). Pass the address of the
variable to the call.
name part, but I don't know how to use that call:
Here is my code for name part:

#include <iostream>
#include <windows.h>
using namespace std;

int main(int argc, char *argv[])
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
char host[500];
DWORD bufferLength;
GetComputerName(host, &bufferLength);
cout << "Host name is " << host << endl;
GetUserName(host, &bufferLength);
cout << "User is " << host << endl;
SetConsoleTitle("prog2");
}

Anyone could help me with that time part, for I really don't know how
to use that! Thank you very very much!

Sincerely,
Ben
 
M

mlimber

Hi all!
I have a question regarding a windows operating system function:
I was asked to write a small program for a homework to display the
user name and computer name and the system time out to a console
window: the display would be like:
Hello XXX(user)
Today is XXX(date)
The Time is XXX(current system time)

I was asked to use a Windows System Call---void GetLocalTime(SYSTIME
*lpSystemTime) for the time part. I have done the user and computer
name part, but I don't know how to use that call:
Here is my code for name part:

#include <iostream>
#include <windows.h>
using namespace std;

int main(int argc, char *argv[])
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
char host[500];
DWORD bufferLength;
GetComputerName(host, &bufferLength);
cout << "Host name is " << host << endl;
GetUserName(host, &bufferLength);
cout << "User is " << host << endl;
SetConsoleTitle("prog2");

}

Anyone could help me with that time part, for I really don't know how
to use that! Thank you very very much!

This is a Windows-specific question, and should be asked on a Windows-
specific group. See the partial list in this FAQ:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Cheers! --M
 
A

Andre Kostur

Hi all!
I have a question regarding a windows operating system function:
I was asked to write a small program for a homework to display the
user name and computer name and the system time out to a console
window: the display would be like:
Hello XXX(user)
Today is XXX(date)
The Time is XXX(current system time)

I was asked to use a Windows System Call---void GetLocalTime(SYSTIME
*lpSystemTime) for the time part. I have done the user and computer
name part, but I don't know how to use that call:
Here is my code for name part:

#include <iostream>
#include <windows.h>
using namespace std;

int main(int argc, char *argv[])
{
HANDLE handle = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleTextAttribute(handle, FOREGROUND_GREEN);
char host[500];
DWORD bufferLength;
GetComputerName(host, &bufferLength);
cout << "Host name is " << host << endl;
GetUserName(host, &bufferLength);
cout << "User is " << host << endl;
SetConsoleTitle("prog2");

}

Anyone could help me with that time part, for I really don't know how
to use that! Thank you very very much!

This is a Windows-specific question, and should be asked on a Windows-
specific group. See the partial list in this FAQ:

http://www.parashift.com/c++-faq-lite/how-to-post.html#faq-5.9

Presumably you'll want to declare a variable of type SYSTIME, and pass
its address to GetLocalTime():

SYSTIME systemTime;

GetLocalTime(&systemTime);


Other than that, you'll have to use the documentation that came with your
compiler to determine what other behaviours GetLocalTime may have, and
what's actually in an object of type SYSTIME.
 
Z

zeppe

Andre said:
Presumably you'll want to declare a variable of type SYSTIME, and pass
its address to GetLocalTime():

No, presumably the question is OT and you replied to the wrong post
with an answer that has already been given.

For the OP:
if you want a standard solution, anyway:

ctime(time(NULL));

or for a very portable one use boost libraries.

Regards,

Zeppe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top