•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the C++ section within the Software Development category of DaniWeb, a massive community of 427,680 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,298 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our C++ advertiser: Programming Forums
Views: 2064 | Replies: 7 | Solved
![]() |
•
•
Join Date: Dec 2006
Posts: 19
Reputation:
Rep Power: 2
Solved Threads: 0
Hi
I am new to c++. I tried to get current date but when I compile the program, it gives me an error. This is my program
when I complie in cygwin, the error is
test.cpp:8: error: รข was not declared in this scope
Where are am I making a mistake. Please help me. Its urgent. Thanks a lot in advance.
I am new to c++. I tried to get current date but when I compile the program, it gives me an error. This is my program
cplusplus Syntax (Toggle Plain Text)
#include <iostream> #include <ctime> #include <stdio.h> int main () { char sdate [10]; _strdate(sdate); std::cout<<"Current Date:"<<sdate; return 0; }
test.cpp:8: error: รข was not declared in this scope
Where are am I making a mistake. Please help me. Its urgent. Thanks a lot in advance.
Last edited by ~s.o.s~ : Dec 13th, 2006 at 9:22 pm. Reason: Added code tags learn to use them yourself.
•
•
Join Date: May 2006
Location: Bellevue, WA
Posts: 1,548
Reputation:
Rep Power: 8
Solved Threads: 51
Here is the reference site.
Here is a small example:
Here is a small example:
cplusplus Syntax (Toggle Plain Text)
#include <iostream> #include <ctime> using namespace std ; int main( ) { char buffer[BUFSIZ] = { '\0' } ; time_t now = time( &now ) ; struct tm* local_time = new tm( ) ; local_time = localtime( &now ) ; strftime( buffer, BUFSIZ, "%d / %m / %Y", local_time ) ; cout << buffer ; }
I don't accept change. I don't deserve to live.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
Happiness corrupts people.
Failing to value the lives of others cheapens your own.
•
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,222
Reputation:
Rep Power: 38
Solved Threads: 934
or this, which is almost identical to what ~S.O.S.~ posted. Like most things in programming there is always more than one way to do it. Unless you are instructed to do otherwise you can choose whichever method you want. One is not any better than the other unless you make the buffer too small to hold the result. In that case neither version will work correctly.
#include <iostream>
#include <ctime>
using namespace std ;
int main( )
{
char buffer[BUFSIZ] = { '\0' } ;
time_t now = time( &now ) ;
struct tm* local_time = new tm( ) ;
local_time = localtime( &now ) ;
sprintf(buffer,"%02d/%02d/%04d",
local_time->tm_mday,
local_time->tm_mon+1,
local_time->tm->year+1900);
cout << buffer ;
} I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Isn't this leaking memory (aside from the fact that no attempt is made to delete the lost memory)? It is also a good habit to check return values.
Time - Displaying Current
Change the format fed to
struct tm* local_time = new tm( ) ; local_time = localtime( &now ) ;
Time - Displaying Current
Change the format fed to
strftime, as already mentioned, for the date. •
•
Join Date: Aug 2005
Location: near St Louis, Missouri, USA
Posts: 11,222
Reputation:
Rep Power: 38
Solved Threads: 934
I think it's about time we voted for senators with breasts. After all, we've been voting for boobs long enough. ~Clarie Sargent, Arizona senatorial candidate
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
Those who are too smart to engage in politics are punished by being governed by those who are dumber. ~Plato
![]() |
•
•
•
•
•
•
•
•
DaniWeb C++ Marketplace
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
Similar Threads
- How to get the current date in JAVA (JSP)
- How to Get Last Accessed/Created/Modified File Date and Time (C)
- ASP Date Help - If Then Else (ASP)
- How to Add date to file Name (Windows NT / 2000 / XP / 2003)
- Passing data from forms from one page to another (JavaScript / DHTML / AJAX)
- Actual Date to Day of the Week Application (Java)
- gwt the record which match the current date (Visual Basic 4 / 5 / 6)
Other Threads in the C++ Forum
- Previous Thread: help with dynamically allocated arrays
- Next Thread: quick questions



Linear Mode