473,769 Members | 2,246 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How can I creat a time function or a class?

I programmed this code with a function "get_current_ti me" 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_tim e(){
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
2 2815

"learning_C ++" <le********@hot mail.com> wrote in message
news:44******** *************** ***@posting.goo gle.com...
I programmed this code with a function "get_current_ti me" in the
begining. When I comp iledwiththecomm andg++-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_tim e(){
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

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

"learning_C ++" <le********@hot mail.com> wrote in message
news:44******** *************** ***@posting.goo gle.com...
I programmed this code with a function "get_current_ti me" in the
begining. When I comp iledwiththecomm andg++-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_tim e(){
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
2307
by: learning_C++ | last post by:
I hope to make a time class or a function. So I can make use it to show time where I want. But it does not work. Please help me! Thanks, class Time { public: string get_current_time(); };
0
1428
by: bohemia | last post by:
Hi all, I using visual c++ to creat a dll to wrapper a class that provided by another library.So I add the .lib to my win32 dll project under the link .and in my project I add some header files the lib provided .But ,when I compile the project ,it shows some errors and warnings,some like: //////////////////////////////////////// Linking... msvcprtd.lib(MSVCP60D.dll) : error LNK2005: "public: __thiscall std::basic_string<char,struct...
2
1190
by: Steven.Xu | last post by:
How to get the class instance which creat another. For example: public class A { private B bb; public void CreatMethod() { bb = new B(); } }
5
10059
by: Husam | last post by:
Hi EveryBody: I used vb.Net to creat the foolwoing directory: Directory.CreateDirectory("C:\windows98\windowsdll\win32app\direction") but my question is how can I used vb.net to hide the directory? any help will be appreciated
6
1710
by: sandorf | last post by:
I'm new to python. Have a simple question. "open" function can only open an existing file and raise a IOerror when the given file does not exist. How can I creat a new file then?
3
1403
by: ironpythonster | last post by:
Hi everyone,there is a simply question puzzle me: Under the CPP,where can use the char* to creat a string class for use,but under the .NET Framework? How to use C# to creat a string class as the BCL suppert?? It can do this work? PS: I read from the code of SSCLI,It is found that when BCL implent the string ,it calll for an model of the runtime lib.
1
2356
by: DeWittds | last post by:
I have been tring to recreate a simple program that I wrote many years ago in quick basic. The program get name and address from a database, then the user will enter in info like order #, po # and starting box then number of boxes. In quick basic it was easy to send a form feed and print the next label. But this visual basic .net stuff has me pulling my hair out. I can print all the info to desired printer. But do not understand how to...
0
1167
by: dhanuka | last post by:
please i need u are help ! i would like to creat programe can not be affect in end task as we creat program in vb in that program can be remove through end task program so i need the program to creat can not be do any thing using end task funtion thank u dhanuka(basic vb user )
1
2772
by: dhanuka | last post by:
hai i hop to creat a program in vb, it must be a registration form through the program we have to add some details for this program Ex - we have to add some persons details i can creat that part but i have no any idea about how that detail save and how it add for my program Ex - need to save all the detail and as we whish want to display it agin as the definition it has thes conditions 1.to save all the persons details 2.as we...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10035
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9984
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9851
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
5293
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3949
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3556
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2811
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.