By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,712 Members | 1,430 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,712 IT Pros & Developers. It's quick & easy.

a question regarding system time.

P: n/a
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

Apr 19 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a

"Benny Van" <fy********@gmail.comwrote in message
news:11**********************@b58g2000hsg.googlegr oups.com...
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

Apr 19 '07 #2

P: n/a
On Apr 19, 4:30 pm, Benny Van <fyf5555...@gmail.comwrote:
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-lit...t.html#faq-5.9

Cheers! --M

Apr 19 '07 #3

P: n/a
mlimber <ml*****@gmail.comwrote in news:1177019552.388923.166420
@o5g2000hsb.googlegroups.com:
On Apr 19, 4:30 pm, Benny Van <fyf5555...@gmail.comwrote:
>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-lit...t.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.
Apr 19 '07 #4

P: n/a
Andre Kostur wrote:
mlimber <ml*****@gmail.comwrote in news:1177019552.388923.166420
@o5g2000hsb.googlegroups.com:
>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-lit...t.html#faq-5.9

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
Apr 20 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.