String

L

Latina

If I am storing the date the user enters, how I can know what the
month, day and year is.
Ex: November 20, 2007
Can some one help me to code that?
Thanks
 
C

Christopher Pisz

Latina said:
If I am storing the date the user enters, how I can know what the
month, day and year is.
Ex: November 20, 2007
Can some one help me to code that?
Thanks

Well, one way is to refer to your favorite reference, and look up time_t,
localtime, asctime, and other goodies found in the <ctime> header. Another
is to roll your own using std::string's find, erase, replace, substr, and
other goodies found in the <string> header. After you do that I am sure the
folks here will be willing to help you with more specific questions, if you
supply your best attempt at a compilable example.
 
V

Victor Bazarov

Latina said:
If I am storing the date the user enters, how I can know what the
month, day and year is.
Ex: November 20, 2007
Can some one help me to code that?

Sure. How much are you willing to shell out? My rates are pretty high.

V
 
A

alan

Sure. How much are you willing to shell out? My rates are pretty high.
I'll charge 80% of what Victor will charge (terms and conditions
apply. see posters and print ads for details).
 
T

Tadeusz B. Kopec

If I am storing the date the user enters, how I can know what the month,
day and year is.
Ex: November 20, 2007
Can some one help me to code that?
Thanks

Today is November 21, 2007.
The code is

std::cout << "November 21, 2007" << std::endl;

No charge.
 
C

Christopher

Today is November 21, 2007.
The code is

std::cout << "November 21, 2007" << std::endl;

No charge.


Lol. That is mean. I know we all assume it is a homework question, but
it may just be a matter of the OP not knowing how to ask the question.
We'll see if the OP can come back and rephrase the question properly.
 
R

red floyd

Christopher said:
Lol. That is mean. I know we all assume it is a homework question, but
it may just be a matter of the OP not knowing how to ask the question.
We'll see if the OP can come back and rephrase the question properly.

Having seen some of the OP's other posts, I'm assuming it's a homework.
 
D

David Harmon

On Tue, 20 Nov 2007 21:34:28 -0800 (PST) in comp.lang.c++, Latina
If I am storing the date the user enters, how I can know what the
month, day and year is.
Ex: November 20, 2007

There are many ways to attack that kind of problem, and no one
predefined "best" way. The biggest question is how much variability are
you prepared to accommodate in what the user has typed.

I would probably begin by splitting the string into the chunks you want
to look at. You might do that with std::istringstream, but I'd probably
choose either my own splitter function or else boost::regex. For more
on those topics see
http://groups.google.com/[email protected]

I would definitely consider std::map<std::string,int> for the job of
translating month names and abbreviations to the month number.

Remember, post your own attempt at solving the problem when asking
questions if you want people to take seriously your intention to learn.
See "[5.8] How do I post a question about code that doesn't work
correctly?" in Marshall Cline's C++ FAQ. It is always good to check the
FAQ before posting. You can get the FAQ at:
http://www.parashift.com/c++-faq-lite/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,196
Messages
2,571,036
Members
47,631
Latest member
kukuh

Latest Threads

Top