Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > a question regarding system time.

Reply
Thread Tools

a question regarding system time.

 
 
Benny Van
Guest
Posts: n/a
 
      04-19-2007
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

 
Reply With Quote
 
 
 
 
Jim Langston
Guest
Posts: n/a
 
      04-19-2007

"Benny Van" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) 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
>



 
Reply With Quote
 
 
 
 
mlimber
Guest
Posts: n/a
 
      04-19-2007
On Apr 19, 4:30 pm, Benny Van <(E-Mail Removed)> wrote:
> 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

 
Reply With Quote
 
Andre Kostur
Guest
Posts: n/a
 
      04-19-2007
mlimber <(E-Mail Removed)> wrote in news:1177019552.388923.166420
@o5g2000hsb.googlegroups.com:

> On Apr 19, 4:30 pm, Benny Van <(E-Mail Removed)> wrote:
>> 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.
 
Reply With Quote
 
zeppe
Guest
Posts: n/a
 
      04-20-2007
Andre Kostur wrote:
> mlimber <(E-Mail Removed)> wrote 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Regarding system function sunil C Programming 12 10-09-2006 11:05 AM
Beginner question regarding the use of system() commands AG C Programming 8 04-23-2006 03:50 PM
Beta 2 question regarding System.Net.Mail Mantorok ASP .Net 0 08-18-2005 04:25 PM
System.Security.SecurityException: Error de solicitud de permiso de tipo System.Net.WebPermission, System, Version=1.0.5000.0, Culture=neutral, PublicKeyToken=b77a5c561934e089. Luis Esteban Valencia ASP .Net 0 07-14-2005 01:43 PM
regarding system function praba kar Python 1 04-22-2005 06:53 AM



Advertisments