a question regarding system time.

Discussion in 'C++' started by Benny Van, Apr 19, 2007.

  1. Benny Van

    Benny Van Guest

    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
    Benny Van, Apr 19, 2007
    #1
    1. Advertising

  2. Benny Van

    Jim Langston Guest

    "Benny Van" <> wrote in message
    news:...
    > 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
    >
    Jim Langston, Apr 19, 2007
    #2
    1. Advertising

  3. Benny Van

    mlimber Guest

    On Apr 19, 4:30 pm, Benny Van <> 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-lite/how-to-post.html#faq-5.9

    Cheers! --M
    mlimber, Apr 19, 2007
    #3
  4. Benny Van

    Andre Kostur Guest

    mlimber <> wrote in news:1177019552.388923.166420
    @o5g2000hsb.googlegroups.com:

    > On Apr 19, 4:30 pm, Benny Van <> 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-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.
    Andre Kostur, Apr 19, 2007
    #4
  5. Benny Van

    zeppe Guest

    Andre Kostur wrote:
    > mlimber <> 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-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():


    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
    zeppe, Apr 20, 2007
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lawrance
    Replies:
    0
    Views:
    457
    Lawrance
    Nov 30, 2003
  2. Mantorok
    Replies:
    0
    Views:
    360
    Mantorok
    Aug 18, 2005
  3. flamesrock
    Replies:
    8
    Views:
    451
    Hendrik van Rooyen
    Nov 24, 2006
  4. AG
    Replies:
    8
    Views:
    336
    Andrew Poelstra
    Apr 23, 2006
  5. deepak
    Replies:
    1
    Views:
    30,558
    Kevin Spencer
    Feb 6, 2008
Loading...

Share This Page