473,704 Members | 2,897 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 2810

"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
2304
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
1423
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
1186
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
10054
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
1707
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
1400
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
2354
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
1166
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
2767
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
8767
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
9272
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9026
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
8977
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
7891
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4439
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...
0
4701
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3135
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
3
2080
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.