How can I creat a time function or a class?

Discussion in 'C++' started by learning_C++, Sep 23, 2004.

  1. learning_C++

    learning_C++ Guest

    I programmed this code with a function "get_current_time" in the
    begining. When I compiled with the command g++ -Wall -g xxx.xpp -o xxx
    there are so many errors.
    please help me and thanks,

    #include <map>
    #include <iostream>
    #include <iomanip>
    #include <string>
    #include <time.h>

    //using namespace std;


    string get_current_time(){
    string timestr;
    time_t rawtime;
    struct tm * timeinfo;
    time_t time ( &rawtime );
    timeinfo = localtime ( &rawtime );
    timestr=asctime(timeinfo);
    }
    bank.cpp:14: error: invalid conversion from `time_t*' to `int'
    bank.cpp:15: error: ISO C++ forbids declaration of `timeinfo' with no
    type
    bank.cpp:15: error: conflicting types for `int timeinfo'
    bank.cpp:13: error: previous declaration as `tm*timeinfo'
    bank.cpp:16: error: ISO C++ forbids declaration of `timestr' with no
    type
    bank.cpp:16: error: invalid conversion from `int' to `const tm*'
    bank.cpp:16: error: invalid conversion from `char*' to `int'
    bank.cpp:17: error: parse error before `}' token
    learning_C++, Sep 23, 2004
    #1
    1. Advertising

  2. "learning_C++" <> wrote in message
    news:...
    >I programmed this code with a function "get_current_time" in the
    > begining. When I comp iledwiththecommandg++-Wall-gxxx.xpp-oxxx
    > there are so many errors.
    > please help me and thanks,
    >
    > #include <map>
    > #include <iostream>
    > #include <iomanip>
    > #include <string>
    > #include <time.h>
    >
    > //using namespace std;
    >
    >
    > string get_current_time(){
    > string timestr;
    > time_t rawtime;
    > struct tm * timeinfo;
    > time_t time ( &rawtime );


    time(&rawtime);

    Because you put 'time_t time(&rawtime);' the compiler thinks you are trying
    to declare a variable called time.

    > timeinfo = localtime ( &rawtime );
    > timestr=asctime(timeinfo);
    > }


    john
    John Harrison, Sep 23, 2004
    #2
    1. Advertising

  3. "John Harrison" <> wrote in message
    news:...
    >
    > "learning_C++" <> wrote in message
    > news:...
    >>I programmed this code with a function "get_current_time" in the
    >> begining. When I comp iledwiththecommandg++-Wall-gxxx.xpp-oxxx
    >> there are so many errors.
    >> please help me and thanks,
    >>
    >> #include <map>
    >> #include <iostream>
    >> #include <iomanip>
    >> #include <string>
    >> #include <time.h>
    >>
    >> //using namespace std;
    >>
    >>
    >> string get_current_time(){
    >> string timestr;
    >> time_t rawtime;
    >> struct tm * timeinfo;
    >> time_t time ( &rawtime );

    >
    > time(&rawtime);
    >
    > Because you put 'time_t time(&rawtime);' the compiler thinks you are
    > trying to declare a variable called time.
    >
    >> timeinfo = localtime ( &rawtime );
    >> timestr=asctime(timeinfo);


    Also

    return timestr;

    If you want to return a value from a function you must say return. It
    doesn't happen by magic.

    john
    John Harrison, Sep 23, 2004
    #3
    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. CM
    Replies:
    3
    Views:
    1,685
  2. John

    Can creat asp.net apps

    John, Nov 6, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    387
    Daniel Rimmelzwaan
    Nov 7, 2003
  3. learning_C++

    How can I creat a time class?

    learning_C++, Sep 22, 2004, in forum: C++
    Replies:
    4
    Views:
    387
    Evan Carew
    Sep 23, 2004
  4. Angus
    Replies:
    10
    Views:
    563
    Juha Nieminen
    Aug 16, 2011
  5. Jerry Lee

    How we can creat this?

    Jerry Lee, Sep 20, 2005, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    170
    Tasos Vogiatzoglou
    Sep 21, 2005
Loading...

Share This Page