N
nileshkaria
Here is an example of what I'm trying to do:
Date(const unsigned d, const char* const m, const unsigned y,
std::locale const & r_loc = std::locale::global(std::locale("")))
{
// Some code here to read and verify whether m is a valid month.
If true then execute the line below. A valid month is the full month
name or its 3 letter abbreviation eg. January, Jan. Anything else read
in should generate an exception. Though reading in a month which is
valid in another locale should be allowed by setting the locale
accordingly first.
date_ = date(d, month, y);
// date_ is of type boost::gregorian::date.
// ...some code here...
}
Also, instead of reading d, m and y as above, if we were to pass the
date as a string in the format %m/%d/%Y, (eg. 06/29/2006) how do we
convert it using a user-defined locale into a boost::Gregorian::date?
Of course we should be able to pass a user-defined locale and format
accordingly; say for eg. the date is read in through the console as
%m/%d/%y. How do I set the locale so that it reads in string as such?
'm also trying to figure out the same thing for reading and writing
streams as well depending upon the locale specified using %a, %b etc.
It'd be great if someone could provide some code from where I can start
off. Thanks in advance!
-Nilesh
Date(const unsigned d, const char* const m, const unsigned y,
std::locale const & r_loc = std::locale::global(std::locale("")))
{
// Some code here to read and verify whether m is a valid month.
If true then execute the line below. A valid month is the full month
name or its 3 letter abbreviation eg. January, Jan. Anything else read
in should generate an exception. Though reading in a month which is
valid in another locale should be allowed by setting the locale
accordingly first.
date_ = date(d, month, y);
// date_ is of type boost::gregorian::date.
// ...some code here...
}
Also, instead of reading d, m and y as above, if we were to pass the
date as a string in the format %m/%d/%Y, (eg. 06/29/2006) how do we
convert it using a user-defined locale into a boost::Gregorian::date?
Of course we should be able to pass a user-defined locale and format
accordingly; say for eg. the date is read in through the console as
%m/%d/%y. How do I set the locale so that it reads in string as such?
'm also trying to figure out the same thing for reading and writing
streams as well depending upon the locale specified using %a, %b etc.
It'd be great if someone could provide some code from where I can start
off. Thanks in advance!
-Nilesh