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

How can I creat a time function or a class?

P: n/a
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
Jul 22 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a

"learning_C++" <le********@hotmail.com> wrote in message
news:44**************************@posting.google.c om...
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
Jul 22 '05 #2

P: n/a

"John Harrison" <jo*************@hotmail.com> wrote in message
news:2r*************@uni-berlin.de...

"learning_C++" <le********@hotmail.com> wrote in message
news:44**************************@posting.google.c om...
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
Jul 22 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.